Merging EPS, PostScript (PS), and XPS documents in Java

Combine multiple EPS, PostScript (PS), and XPS files into single, multi-page PDF documents programmatically using Aspose.Page for Java. Merge individual vector graphics, print files, or page streams seamlessly across different document formats without relying on Adobe Acrobat, Distiller, or native Windows print utilities.

 

Aspose.Page for Java merges documents through the document classes themselves: PsDocument.mergeToPdf() combines PostScript and EPS files into one PDF, and XpsDocument.merge() combines XPS documents into a single XPS file. Save options such as additional fonts folders and error handling are passed through PdfSaveOptions.

  • To combine isolated vector graphics and EPS illustrations into a consolidated PDF portfolio use PsDocument.mergeToPdf() method.
  • To merge multi-file PostScript print jobs and reports into a single printable PDF file use PsDocument.mergeToPdf() method.
  • To combine disparate XPS files, invoices, or batch page outputs into a single XPS or PDF package use XpsDocument.merge() method.

Merge multiple EPS files into a single PDF

Merge an array of separate EPS vector graphic files into a single multi-page PDF document.

// Merge several EPS files to one PDF document.
// Learn more: https://docs.aspose.com/page/java/merge/ps/

// Initialize PS document with the first EPS file
PsDocument document = new PsDocument(getDataDir() + "input.eps");

// Create an array of PostScript files that will be merged with the first one
String[] filesForMerge = new String[] { getDataDir() + "input2.eps", getDataDir() + "input3.eps" };

// 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 SaveOptions
// But if you need to specify the page size following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new java.awt.Dimension(595, 842));

document.mergeToPdf(getOutputDir() + "outputPDF_out.pdf", filesForMerge, options);

//Review errors
if (suppressErrors) {
    for (Exception ex : options.getExceptions()) {
        System.out.println(ex.getMessage());
    }
}

Merge multiple PostScript (PS) documents into a single PDF

Combine multiple multi-page PostScript files into a consolidated PDF stream using custom font search paths and options.

// Merge several PS files to one PDF document.
// Learn more: https://docs.aspose.com/page/java/merge/ps/

// Initialize PS document with the first PostScript file
PsDocument document = new PsDocument(getDataDir() + "input.ps");

// Create an array of PostScript files that will be merged with the first one
String[] filesForMerge = new String[] { getDataDir() + "input2.ps", getDataDir() + "input3.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 SaveOptions
// But if you need to specify the page size following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new java.awt.Dimension(595, 842));

document.mergeToPdf(getOutputDir() + "outputPDF_out.pdf", filesForMerge, options);

//Review errors
if (suppressErrors) {
    for (Exception ex : options.getExceptions()) {
        System.out.println(ex.getMessage());
    }
}

Merge multiple XPS documents into a single XPS File

Combine disparate XPS packages or generated invoice pages into a single multi-page XPS file.

// Merge several XPS files to one XPS document.
// Learn more: https://docs.aspose.com/page/java/merge/xps/

// Load XPS document from XPS file
XpsDocument document = new XpsDocument(getDataDir() + "input.xps");

// Create an array of XPS files that will be merged with the first one
String[] filesToMerge = new String[] { getDataDir() + "Demo.xps", getDataDir() + "sample.xps" };

// Merge XPS files to output XPS document
document.merge(filesToMerge, getOutputDir() + "mergedXPSfiles.xps");

Installation and Setup

Add Aspose.Page for Java to your Maven:

Package Manager Console Command

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-page</artifactId>
    <version>Latest</version>
</dependency>

FAQ

1. Can I merge XPS documents directly to PDF instead of XPS?

Yes. You can load an XPS document using XpsDocument and render it along with secondary files using PdfDevice to create a merged PDF file directly from XPS inputs.

2. How does Aspose.Page handle missing fonts when merging PS or EPS files?

If custom fonts are referenced in the input EPS/PS files, you can supply their location using PdfSaveOptions.setAdditionalFontsFolders(). If missing, Aspose.Page uses built-in default font substitution logic to complete rendering without throwing fatal exceptions.

3. Is memory efficiency preserved during batch processing of large file sets?

Yes. Aspose.Page processes input page streams sequentially during PDF device execution, allowing large enterprise print jobs to be combined efficiently with low memory overhead.