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// 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();
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// 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();
You can download examples and data files from GitHub.