在 PS 文件中使用页面 | Java

Contents
[ Hide Show ]

向 PS 文档添加页面

Aspose.Page for Java 提供了两种向 PsDocument 对象添加页面的方法。
以下代码片段通过 8 个步骤创建一个 2 页的 PS 文档:

  1. 为生成的 PS 文件创建输出流。
  2. 使用默认选项创建 PsSaveOptions 对象。
  3. 使用已创建的输出流和保存选项创建一个 2 页的 PsDocument。
  4. 使用文档的默认页面尺寸(纵向 A4 尺寸)打开第一页。
  5. 关闭页面。
  6. 使用新的尺寸打开第二页。
  7. 关闭页面。
  8. 保存文档。
 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();
Example-AddPagePS1.java hosted with ❤ by GitHub

请参阅在 .NET 中处理 PS 文档中的页面。

以下代码片段同样创建了一个两页的 PS 文档,但包含 7 个步骤:

  1. 为生成的 PS 文件创建输出流。
  2. 使用默认选项创建 PsSaveOptions 对象。
  3. 使用已创建的输出流和保存选项创建多页 PsDocument。在本例中,第一页已打开,其大小为文档的默认页面大小(纵向 A4 尺寸)。
  4. 关闭页面。
  5. 以新的大小打开第二页。
  6. 关闭页面。
  7. 保存文档。 当文档只有 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();
Example-AddPagePS2.java hosted with ❤ by GitHub

您可以从 GitHub下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.