apache odftoolkit portrait / landscape mode

时间:2017-10-05 07:46:46

标签: odftoolkit

我使用库apache odftoolkit生成从Java代码到* .odt文件的报告。有这样的代码:

outputOdt = TextDocument.newTextDocument();
Paragraph p = outputOdt.addParagraph("some text");
p.appendTextContent("some text");

我添加段落,表格,设置字体,它工作正常。 但我需要在横向模式下在我的文档中设置一些页面,但是 不知道该怎么做。我找到了API类PageLayoutProperties和方法setPrintOrientation(),但不知道在哪里调用它。有人知道吗?

2 个答案:

答案 0 :(得分:0)

找到解决方案:

TextDocument outputOdt;
for( Iterator<StyleMasterPageElement> it = outputOdt.getOfficeMasterStyles().getMasterPages(); it.hasNext(); ) {
            StyleMasterPageElement page = it.next();
            String pageLayoutName = page.getStylePageLayoutNameAttribute();
            OdfStylePageLayout pageLayoutStyle = page.getAutomaticStyles().getPageLayout( pageLayoutName );
            PageLayoutProperties pageLayoutProps = PageLayoutProperties.getOrCreatePageLayoutProperties( pageLayoutStyle );

            double tmp = pageLayoutProps.getPageWidth();
            pageLayoutProps.setPageWidth( pageLayoutProps.getPageHeight());
            pageLayoutProps.setPageHeight( tmp );
        }

答案 1 :(得分:0)

我遇到了这个现有的问题和答案:

How can the Page Size, Page Orientation, and Page Margins of an ods Spreadsheet Be Set Using ODFDOM?

这对于ODS电子表格执行相同的操作,本质上是相同的。关键是在PageLayoutProperties

中设置页面的高度和宽度以及打印方向
相关问题