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:

  1. Create an instance of PsDocument from the first PostSctipt file.
  2. Create an array of PostSctipt files that will be merged with the first one.
  3. Use PdfSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
  4. Merge PS files with created document and save it as PDF with PDF save options.
  5. 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.


Following code snippet shows how to merge PS files to PDF document in Java:

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2
 3        // The path to the documents directory.
 4        String dataDir = Utils.getDataDir();
 5
 6				// Initialize PS document from PostScript file.
 7        PsDocument document = new PsDocument(dataDir + "input.ps");
 8        
 9        // Create an array of PostScript files that will be merged with the first one
10        String[] filesForMerge = new String[] { dataDir + "input2.ps", dataDir + "input3.ps" };
11
12        // If you want to merge PostScript file despite of minor errors set this flag
13        boolean suppressErrors = true;
14
15        //Initialize options object with necessary parameters.
16        PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
17        // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
18        //options.setAdditionalFontsFolders(new String [] {"FONTS_FOLDER"});
19        // Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
20        // But if you need to specify size use following line
21        // PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Dimension(595, 842));
22
23        // Merge files with initialized PsDocument and save it as PDF
24        document.mergeToPdf(dataDir + "mergePStoPDF.pdf", filesForMerge, options);
25
26        //Review errors
27        if (suppressErrors) {
28            for (Exception ex : options.getExceptions()) {
29                System.out.println(ex.getMessage());
30            }
31        }

See PS merge in .NET and C++.

Let’s consider PdfSaveOptions. Using this class we can assign different conversion parameters while merging PS files to PDF.

Evaluate PS merging online on our PS Merger.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.