我正在使用库apache生成从odftoolkit代码到*.odt文件的报告。代码如下:
outputOdt = TextDocument.newTextDocument();
Paragraph p = outputOdt.addParagraph("some text");
p.appendTextContent("some text");我正在添加段落,表格,设置字体,它工作得很好。但我需要在横向模式下设置文档中的一些页面,但不知道如何执行此操作。我找到了API类PageLayoutProperties和方法setPrintOrientation(),但不知道在哪里调用它。有人知道吗?
发布于 2018-10-03 19:51:49
找到解决方案:
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 );
}发布于 2019-02-07 18:59:51
我遇到了这个现有的问题和答案:
How can the Page Size, Page Orientation, and Page Margins of an ods Spreadsheet Be Set Using ODFDOM?
这是关于对ODS电子表格做同样的事情,本质上是相同的。关键是在PageLayoutProperties中设置页面的高度和宽度以及打印方向
https://stackoverflow.com/questions/46580464
复制相似问题