【问题标题】:apache odftoolkit portrait/landscape modeapache odftoolkit 纵向/横向模式
【发布时间】:2017-10-05 07:46:45
【问题描述】:

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

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

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

【问题讨论】:

标签: odftoolkit


【解决方案1】:

找到解决方案:

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 );
        }

【讨论】:

    【解决方案2】:

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

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

    这就是对 ODS 电子表格做同样的事情,本质上是相同的。关键是在PageLayoutProperties中设置页面高度和宽度以及打印方向

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多