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