在 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// Add page to PS document.
 2
 3string outputFileName = "document1_out.ps";
 4
 5//Create save options with A4 size
 6PsSaveOptions options = new PsSaveOptions();
 7options.Debug = true;
 8
 9// Create new 2-paged PS Document
10PsDocument document = new PsDocument(OutputDir + outputFileName, options, 2);
11
12//Add the first page
13document.OpenPage();
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.cs hosted with ❤ by GitHub

请参阅如何在 Java 中处理 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
     9bool multiPaged = true;
    10
    11// Create new multipaged PS Document with one page opened
    12PsDocument document = new PsDocument(OutputDir + 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.cs 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.