在 PS 文件中使用页面 | Java
Contents
[
Hide
Show
]向 PS 文档添加页面
Aspose.Page for Java 提供了两种向
PsDocument 对象添加页面的方法。
以下代码片段通过 8 个步骤创建一个 2 页的 PS 文档:
- 为生成的 PS 文件创建输出流。
- 使用默认选项创建 PsSaveOptions 对象。
- 使用已创建的输出流和保存选项创建一个 2 页的 PsDocument。
- 使用文档的默认页面尺寸(纵向 A4 尺寸)打开第一页。
- 关闭页面。
- 使用新的尺寸打开第二页。
- 关闭页面。
- 保存文档。
1// Add page to PS document.
2
3String outputFileName = "document1_out.ps";
4
5//Create save options with A4 size
6PsSaveOptions options = new PsSaveOptions();
7options.setDebug(true);
8
9// Create new 2-paged PS Document
10PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, 2);
11
12//Add the first page
13document.openPage(null);
14
15//Add content
16
17//Close the first page
18document.closePage();
19
20//Add the second page with different size
21document.openPage(400, 700);
22
23//Add content
24
25//Close the second page
26document.closePage();
27
28//Save the document
29document.save();请参阅在 .NET 中处理 PS 文档中的页面。
以下代码片段同样创建了一个两页的 PS 文档,但包含 7 个步骤:
- 为生成的 PS 文件创建输出流。
- 使用默认选项创建 PsSaveOptions 对象。
- 使用已创建的输出流和保存选项创建多页 PsDocument。在本例中,第一页已打开,其大小为文档的默认页面大小(纵向 A4 尺寸)。
- 关闭页面。
- 以新的大小打开第二页。
- 关闭页面。
- 保存文档。 当文档只有 1 页或者不知道它是 1 页还是 2 页文档时,这种添加页面的方式很有用。
1// Another way to add page to PS document.
2
3String outputFileName = "document2_out.ps";
4
5//Create save options with A4 size
6PsSaveOptions options = new PsSaveOptions();
7
8//Set variable that indicates if resulting PostScript document will be multipaged
9boolean multiPaged = true;
10
11// Create new multipaged PS Document with one page opened
12PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, multiPaged);
13
14//Add content
15
16//Close the first page
17document.closePage();
18
19//Add the second page with different size
20document.openPage(500, 300);
21
22//Add content
23
24//Close the second page
25document.closePage();
26
27//Save the document
28document.save();您可以从 GitHub下载示例和数据文件。