Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save aspose-com-gists/15dcb5eff71a07b3ea7853a0d4ce93e3 to your computer and use it in GitHub Desktop.
Convert PostScript to PDF and images with Java

PS Conversion Examples

These code snippets show how to convert PostScript (PS) files to other formats using Aspose.Page for Java. The library provides robust tools for transforming PS/EPS documents into PDF, images, and more.

Key Use Cases

  • Convert PS files to PDF.
  • Convert PS files to raster images (PNG, JPEG, BMP).
  • Automate PS/EPS conversion for archiving or publishing.

How to Run Examples

  1. Ensure Aspose.Page for Java is referenced in your project.
  2. Copy the relevant 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, input PS/EPS file is limited to 500Kb. Set up a valid temporary or paid license to unlock full functionality.

Related Documentation

See Convert PS to PDF and Images and Convert EPS to PDF and Images in the official documentation for more information.

Related Resources

Requirements

  • Java 8 or higher
  • Aspose.Page for Java library
Aspose.Page for Java – Convert PS Examples
// Convert EPS file to BMP image.
// Learn more: https://docs.aspose.com/page/java/convert-eps/
//Outut file
String outputFileName = "output_image_from_eps.bmp";
// Initialize PsDocument with the name of EPS file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.eps");
// If you want to convert EPS file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.BMP);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save EPS file as raster image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert EPS file to GIF image.
// Learn more: https://docs.aspose.com/page/java/convert-eps/
//Outut file
String outputFileName = "output_image_from_eps.gif";
// Initialize PsDocument with the name of EPS file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.eps");
// If you want to convert EPS file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.GIF);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save EPS file as raster image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert EPS file to JPEG image.
// Learn more: https://docs.aspose.com/page/java/convert-eps/
//Outut file
String outputFileName = "output_image_from_eps.jpg";
// Initialize PsDocument with the name of EPS file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.eps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.JPEG);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save EPS file as raster image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert EPS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-eps/
// Initialize PsDocument with the name of EPS file.
PsDocument document = new PsDocument(getDataDir() + "input.eps");
// If you want to convert EPS file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, java.awt.Dimension(595x842));
// or
//saveOptions.setSize(new java.awt.Dimension(595x842));
//If PostScript file contains some graphics written as Type3 font glyphs, but it is not actual glyphs
//the resulting PDF may be incorrect because of default value of options.ConvertFontsToTTF = true
//Try to set this
//options.setConvertFontsToTTF(false);
// Save document as PDF
document.saveAsPdf(getOutputDir() + "outputPDF_from_eps_out.pdf", options);
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert EPS file to PNG image.
// Learn more: https://docs.aspose.com/page/java/convert-eps/
//Outut file
String outputFileName = "output_image_from_eps.png";
// Initialize PsDocument with the name of EPS file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.eps");
// If you want to convert EPS file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.PNG);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save EPS file as raster image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert EPS file to TIFF image.
// Learn more: https://docs.aspose.com/page/java/convert-eps/
//Outut file
String outputFileName = "output_image_from_eps.tiff";
// Initialize PsDocument with the name of EPS file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.eps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.TIFF);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save EPS file as raster image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert PS file to BMP image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.bmp";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.BMP);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert PS file to GIF image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.gif";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.GIF);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert PS file to JPEG image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.jpg";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.JPEG);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert PS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, java.awt.Dimension(595x842));
// or
//saveOptions.setSize(new java.awt.Dimension(595x842));
//If PostScript file contains some graphics written as Type3 font glyphs, but it is not actual glyphs
//the resulting PDF may be incorrect because of default value of options.ConvertFontsToTTF = true
//Try to set this
//options.setConvertFontsToTTF(false);
// Save document as PDF
document.saveAsPdf(getOutputDir() + "outputPDF_out.pdf", options);
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert PS file to PNG image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.png";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.PNG);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Convert PS file to TIFF image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.tiff";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.TIFF);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment