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//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}

See working with the pages in PS documents in Java and C++.


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//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}

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.