Working with Pages in PostScript | .NET

Contents
[ Hide Show ]

Add Pages to PS Document

Aspose.Page for .NET offers two ways of adding pages to PsDocument object.

The following code snippet creates a 2-paged PS document in 8 steps:

  1. Create an output stream for the resulting PS file.
  2. Create PsSaveOptions object with default options.
  3. Create a 2-paged PsDocument with an already created output stream and save options.
  4. Open the first page with the default page size of the document (A4 in Portrait orientation).
  5. Close the page.
  6. Open the second page with a new size.
  7. Close the page.
  8. Save the document.
 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

See working with the pages in PS documents in Java.

The following code snippet creates also a 2-paged PS document, but with 7 steps:

  1. Create an output stream for the resulting PS file.
  2. Create PsSaveOptions object with default options.
  3. Create multi-paged PsDocument with already created output stream and save options. In this case, the first page is already opened and its size is the default page size of the document (A4 in Portrait orientation).
  4. Close the page.
  5. Open the second page with a new size.
  6. Close the page.
  7. Save the document. This way of adding pages is useful when the document has 1 page or it is unknown if it will be a 1- or 2-paged document.
 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

You can download examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.