Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/81ab11194ac76cc643fde5787a3f23e3 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/81ab11194ac76cc643fde5787a3f23e3 to your computer and use it in GitHub Desktop.
Convert a Postscript PS or EPS file to PDF Programmatically in Java
// Initialize PDF output stream
FileOutputStream pdfStream = new FileOutputStream(dataDir + "PStoPDF.pdf");
// Initialize PostScript input stream
FileInputStream psStream = new FileInputStream(dataDir + "input.ps");
PsDocument document = new PsDocument(psStream);
// 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);
// Specify PdfDevice object
PdfDevice device = new PdfDevice(pdfStream);
// Convert PS/EPS Postscript file to PDF
try {
document.save(device, options);
} finally {
psStream.close();
pdfStream.close();
}
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
// Initialize PDF output stream
FileOutputStream pdfStream = new FileOutputStream("PStoPDF.pdf");
// Initialize PostScript input stream
FileInputStream psStream = new FileInputStream("input.ps");
// Declare PsDocument class object.
PsDocument document = new PsDocument(psStream);
// 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);
options.setJpegQualityLevel(50);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
//options.setAdditionalFontsFolders(new String [] {"FONTS_FOLDER"});
// If you need to specify size and image format use following line
PdfDevice device = new PdfDevice(pdfStream, new Dimension(595, 842));
// Convert PS/EPS Postscript file to PDF
try {
document.save(device , options);
} finally {
psStream.close();
pdfStream.close();
}
//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