Working with Document in PS file | Java

[ Hide Show ]

Create PS Document

Aspose.Page for Java offers two constructors in order to create PsDocument class. The following code snippet creates a 1-paged PS document:

 1//Create output stream for PostScript document
 2FileOutputStream outPsStream = new FileOutputStream(dataDir + "");
 3//Create save options with A4 size
 4PsSaveOptions options = new PsSaveOptions();
 6//If you want to aassign page size other than A4, set page size in options
 7options.setPageSize(PageConstants.getSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT));
 8//If you want to aassign page margins other than empty, set page margins in options
10//If you plan to use fonts that located in non system folders, set additional fonts folders in options
11options.setAdditionalFontsFolders(new String[] { FONTS_FOLDER });
13//Set variable that indicates if resulting PostScript document will be multipaged
14boolean multiPaged = false;
16// Create new multipaged PS Document with one page opened
17PsDocument document = new PsDocument(outPsStream, options, multiPaged);
19//Close current page
21//Save the document;

If PS document is planning to be multi-paged, set multiPaged variable to true.

Another constructor allows creating PsDocument object with a defined number of pages:

 1//Create save options with A4 size
 2PsSaveOptions options = new PsSaveOptions();
 3//Create output stream for PostScript document
 4FileOutputStream outPsStream = new FileOutputStream(dataDir + "");
 6// Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by addPage() method.
 7PsDocument document = new PsDocument(outPsStream, options, 2);
 9//Close current page
11//Save the document;

See working with PS document in .NET.

Let’s look at the PsSaveOptions class that encapsulates possible options helping to create the right PostScript document.

1options.setPageSize(PageConstants.getSize(PageConstants.SIZE_International, PageConstants.ORIENTATION_PORTRAIT));

The default page size is “A4” in “Portrait” orientation.

1options.setMargins(PageConstants.getMargins(PageConstants.MARGINS_SMALL)); // 20 points for each margin

Default margins are “ZERO” (0, 0, 0, 0).

1options.setBackgroundColor(new Color(211, 8, 48));



Default value is “null” that means no background.


The default value is “TrueType”.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.