Merge PostScript files to PDF using Java
You can check the quality of Aspose.Page PS Merger and view the results via free online PostScipt Merger
Aspose.Page for Java PS Merger allows to merge PostScript (PS) files to PDF document on any OS for which Java Virtual Machine exists.
It is necessary to do several steps in order to perform PS to PDF merge:
- Create an instance of PsDocument from the first PostSctipt file.
- Create an array of PostSctipt files that will be merged with the first one.
- Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
- Merge PS files with created document and save it as PDF with PDF save options.
- If SuppressErrors value was true, as it is by default, It is possible to see what errors were thrown during merging of EPS files to PDF document and saved in Exceptions list.
The following code snippet shows how to merge PS files to PDF document in Java:
1// Merge several PS files to one PDF document.
2
3// Initialize PS document with the first PostScript file
4PsDocument document = new PsDocument(getDataDir() + "input.ps");
5
6// Create an array of PostScript files that will be merged with the first one
7String[] filesForMerge = new String[] { getDataDir() + "input2.ps", getDataDir() + "input3.ps" };
8
9// If you want to convert Postscript file despite of minor errors set this flag
10boolean suppressErrors = true;
11
12//Initialize options object with necessary parameters.
13PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
14// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
15options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
16
17// Default page size is 595x842 and it is not mandatory to set it in SaveOptions
18// But if you need to specify the page size following line
19//PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new java.awt.Dimension(595, 842));
20
21document.mergeToPdf(getOutputDir() + "outputPDF_out.pdf", filesForMerge, options);
22
23//Review errors
24if (suppressErrors) {
25 for (Exception ex : options.getExceptions()) {
26 System.out.println(ex.getMessage());
27 }
28}Let’s consider
PdfSaveOptions. Using this class we can assign different conversion parameters while merging PS files to PDF.
- AdditionalFontsFolder specifies locations where to find fonts. System fonts folders are always included by default.
- SuppressError controls behaviour of PS to PDF merger when non-critical errors are appeared. If value is true than it is possible to view a list of such errors after merging in Exceptions field. Default value is true.
- Debug allows outputting debug information to console. Default value is false.