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:
- Create an output stream for the resulting PS file.
- Create PsSaveOptions object with default options.
- Create a 2-paged PsDocument with an already created output stream and save options.
- Open the first page with the default page size of the document (A4 in Portrait orientation).
- Close the page.
- Open the second page with a new size.
- Close the page.
- 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.
The following code snippet creates also a 2-paged PS document, but with 7 steps:
- Create an output stream for the resulting PS file.
- Create PsSaveOptions object with default options.
- 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).
- Close the page.
- Open the second page with a new size.
- Close the page.
- 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.