This brief tutorial guides on how to convert PS to PDF in Java. A detailed set of steps and a runnable sample code along with the IDE configuration details are shared to convert PostScript file to PDF in Java. Different options for suppressing errors, setting default page size, and other features are also discussed in this article.
Steps to Convert PostScript to PDF in Java
- Set the environment to use Aspose.Page for Java to convert PS to PDF
- Open the source PS file using the FileInputStream
- Instantiate the PsDocument class object using the source PS file stream
- Create a PdfSaveOptions object using the desired suppress errors option
- Create a FileOutputStream object to write the output contents to a PDF
- Instantiate the PdfDevice object using the PDF output stream
- Save the resultant PDF file and close all the streams
These steps summarize the process of converting a PS file to PDF in Java. The process is started by opening the source PS file using the FileInputStream object followed by the creation of the PsDocument object with the aforementioned stream. The PdfDevice class is used to create the Pdf file as it contains the features to save the PDF file using the PdfSaveOptions class object customized for the required output.
Code to Convert PS File to PDF in Java
This code can be used as a basis for the PS to PDF conversion in Java. You can improvise the code by adding the option to select fonts folder using the setAdditionalFontsFolders() method in the PdfSaveOptions class along with customization of other properties for instance setting the JPEG quality. You may change the default page size by using a different constructor of the PdfDevice class by passing the output stream and Dimension object if desired.
This quick guide has taught us the conversion of PostScript file to PDF in Java. If you want to learn the process of converting an EPS file to a PDF file, refer to the article on how to convert EPS to PDF in Java.