在 PostScript 中使用页面 | .NET

Contents
[ Hide Show ]

向 PS 文档添加页面

Aspose.Page for .NET 提供了两种向 PsDocument 对象添加页面的方法。

以下代码片段通过 8 个步骤创建一个 2 页的 PS 文档:

  1. 为生成的 PS 文件创建输出流。
  2. 使用默认选项创建 PsSaveOptions 对象。
  3. 使用已创建的输出流和保存选项创建一个 2 页的 PsDocument。
  4. 使用文档的默认页面尺寸(纵向 A4 尺寸)打开第一页。
  5. 关闭页面。
  6. 使用新的尺寸打开第二页。
  7. 关闭页面。
  8. 保存文档。
 1//Create output stream for PostScript document
 2using (Stream outPsStream = new FileStream(dataDir + "document1.ps", FileMode.Create))
 3{
 4    //Create save options with A4 size
 5    PsSaveOptions options = new PsSaveOptions();
 6
 7    // Create new 2-paged PS Document
 8    PsDocument document = new PsDocument(outPsStream, options, 2);
 9
10    //Add the first page
11    document.OpenPage();
12
13    //Add content
14
15    //Close the first page
16    document.ClosePage();
17
18    //Add the second page with different size
19    document.OpenPage(400, 700);
20
21    //Add content
22
23    //Close the second page
24    document.ClosePage();
25
26    //Save the document
27    document.Save();
28}

请参阅如何在 Java 中处理 PS 文档中的页面。

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

  1. 为生成的 PS 文件创建输出流。
  2. 使用默认选项创建 PsSaveOptions 对象。
  3. 使用已创建的输出流和保存选项创建多页 PsDocument。在本例中,第一页已打开,其大小为文档的默认页面大小(纵向 A4 尺寸)。
  4. 关闭页面。
  5. 以新的大小打开第二页。
  6. 关闭页面。
  7. 保存文档。 当文档只有 1 页或者不知道它是 1 页还是 2 页文档时,这种添加页面的方式很有用。
 1//Create an output stream for PostScript document
 2using (Stream outPsStream = new FileStream(dataDir + "document2.ps", FileMode.Create))
 3{
 4    //Create save options with A4 size
 5    PsSaveOptions options = new PsSaveOptions();
 6
 7    //Set variable that indicates if resulting PostScript document will be multipaged
 8    bool multiPaged = true;
 9
10    // Create new multipaged PS Document with one page opened
11    PsDocument document = new PsDocument(outPsStream, options, multiPaged);
12
13    //Add content
14
15    //Close the first page
16    document.ClosePage();
17
18    //Add the second page with different size
19    document.OpenPage(500, 300);
20
21    //Add content
22
23    //Close the second page
24    document.ClosePage();
25
26    //Save the document
27    document.Save();
28}

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.