Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/2525aaba8cee12a4018fe75fa7db95bd to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/2525aaba8cee12a4018fe75fa7db95bd to your computer and use it in GitHub Desktop.
Create PostScript file from scratch and add pages with Java

Working with PS Document Examples

These code snippets show how to create, modify, and manage PostScript (PS) documents using Aspose.Page for Java. The library provides tools for generating new PS files, adding pages, and manipulating document content.

Key Use Cases

  • Create new PS documents programmatically.
  • Add pages to existing PS files.

How to Run Examples

  1. Reference Aspose.Page for Java in your project.
  2. Copy the required code snippet into your project.
  3. Download a temporary license and set it up as described here or use a paid license.
  4. Run the example.

Restrictions

In evaluation mode, output PS or EPS file is limited to 1Mb and contatins red evaluation warning. Set up a valid temporary or paid license to unlock full functionality.

Related Documentation

See Create and Manipulate PS Documents in the official documentation for more details.

Related Resources

Requirements

  • Java 8 or higher
  • Aspose.Page for Java library
Aspose.Page for Java – Create PS Examples
// Add page to PS document.
// Learn more: https://docs.aspose.com/page/java/ps/working-with-pages/
String outputFileName = "document1_out.ps";
//Create save options with A4 size
PsSaveOptions options = new PsSaveOptions();
options.setDebug(true);
// Create new 2-paged PS Document
PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, 2);
//Add the first page
document.openPage(null);
//Add content
//Close the first page
document.closePage();
//Add the second page with different size
document.openPage(400, 700);
//Add content
//Close the second page
document.closePage();
//Save the document
document.save();
// Another way to add page to PS document.
// Learn more: https://docs.aspose.com/page/java/ps/working-with-pages/
String outputFileName = "document2_out.ps";
//Create save options with A4 size
PsSaveOptions options = new PsSaveOptions();
//Set variable that indicates if resulting PostScript document will be multipaged
boolean multiPaged = true;
// Create new multipaged PS Document with one page opened
PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, multiPaged);
//Add content
//Close the first page
document.closePage();
//Add the second page with different size
document.openPage(500, 300);
//Add content
//Close the second page
document.closePage();
//Save the document
document.save();
// Create new multipaged PS document from scratch.
// Learn more: https://docs.aspose.com/page/java/ps/working-with-document/
String outputFileName = "document_out.ps";
//Create save options
PsSaveOptions options = new PsSaveOptions();
//If you want to aassign page size other than A4, set page size in options
options.setPageSize(PageConstants.getSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT));
//If you want to aassign page margins other empty, set page margins in options
options.setMargins(PageConstants.getMargins(PageConstants.MARGINS_ZERO));
//If you plan to use fonts that located in non system folders, set additional fonts folders in options
options.setAdditionalFontsFolders(new String[] { getDataDir() });
//Set variable that indicates if resulting PostScript document will be multipaged
boolean multiPaged = false;
// Create new multipaged PS Document with one page opened
PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, multiPaged);
//Close current page
document.closePage();
//Save the document
document.save();
// Create new PS document with defined number of pages.
// Learn more: https://docs.aspose.com/page/java/ps/working-with-document/
String outputFileName = "document_out.ps";
//Create save options
PsSaveOptions options = new PsSaveOptions();
//If you want to aassign page size other than A4, set page size in options
options.setPageSize(PageConstants.getSize(PageConstants.SIZE_A4, PageConstants.ORIENTATION_PORTRAIT));
//If you want to aassign page margins other empty, set page margins in options
options.setMargins(PageConstants.getMargins(PageConstants.MARGINS_ZERO));
//If you plan to use fonts that located in non system folders, set additional fonts folders in options
options.setAdditionalFontsFolders(new String[] { getDataDir() });
// Create new multipaged PS Document with 2 pages. These two pages are not created. It must be added by OpenPage() method.
PsDocument document = new PsDocument(getOutputDir() + outputFileName, options, 2);
//Add the first page
document.openPage(null);
//Close current page
document.closePage();
//Save the document
document.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment