1

我正在aspose-words-15.6.0为java使用api。我想根据页码将页面方向更改为portrait or landscape

设想:

doc有 3 页,我希望页面方向如下:

  • 第 1 页:肖像。
  • 第二页:风景。
  • 第三页:肖像。

编辑:

我已经尝试过DocumentBuilder,有一种方法可以实现这一点,但我遗漏了一些东西,请参考我附上这个问题的屏幕截图。

在此处输入图像描述

任何帮助将不胜感激。

4

1 回答 1

3

MS Word 文档中没有 Page 的概念。页面是由 Microsoft Word 动态创建的,不幸的是,没有直接的方法可以用来设置每个页面的方向。但是,您可以使用Section.PageSetup.Orientation属性为整个部分指定方向设置,并且一个部分可能包含多个页面。

或者,您可以使用 Aspose.Words 为 word 文档中的每个页面创建一个单独的部分,然后为与特定页面对应的每个部分指定页面方向。请在Aspose.Words 论坛中报告此要求,然后我们将针对此要求开发代码并为您提供更多信息。

编辑:

如果您想从头开始构建文档,请使用以下代码:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.writeln("Content on first page");
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

builder.writeln("Content on second page");
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

builder.writeln("Content on third page");
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);

doc.save(getMyDir() + "15.10.0.docx");

我与 Aspose 一起担任开发人员宣传员。

于 2015-11-24T07:09:49.673 回答