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 provides specialized rendering devices (PdfDevice, ImageDevice) and save options to convert and combine multiple input files into a unified output stream.
- 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.
import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PdfSaveOptions;
import com.aspose.page.eps.device.PdfDevice;
import java.io.FileOutputStream;
public class MergeEpsFilesToPdf {
public static void main(String[] args) throws Exception {
// Define array of input EPS files to merge
String[] epsFiles = new String[] {
"C:/Project/Input/graphic1.eps",
"C:/Project/Input/graphic2.eps",
"C:/Project/Input/graphic3.eps"
};
// Initialize output stream for the merged PDF
FileOutputStream outStream = new FileOutputStream("C:/Project/Output/merged_eps_output.pdf");
// SOpen the first EPS document as the base document
PsDocument baseDocument = new PsDocument(epsFiles[0]);
// Configure PDF save options
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
// Merge additional EPS files and save to PDF stream
baseDocument.mergeToPdf(outStream, epsFiles, options);
outStream.close();
System.out.println("EPS files successfully merged into a single PDF document.");
}
}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.
import com.aspose.page.eps.PsDocument;
import com.aspose.page.eps.device.PdfSaveOptions;
import java.io.FileOutputStream;
public class MergePsFilesToPdf {
public static void main(String[] args) throws Exception {
// Specify list of PS files
String[] psFiles = new String[] {
"C:/Project/Input/report_part1.ps",
"C:/Project/Input/report_part2.ps"
};
FileOutputStream outStream = new FileOutputStream("C:/Project/Output/merged_report.pdf");
// Load base PS document
PsDocument basePsDoc = new PsDocument(psFiles[0]);
// Set options and configure font folders if custom fonts are used
PdfSaveOptions options = new PdfSaveOptions();
options.setAdditionalFontsFolders(new String[] { "C:/Project/Fonts/" });
// Merge files to PDF
basePsDoc.mergeToPdf(outStream, psFiles, options);
outStream.close();
System.out.println("PostScript documents merged to PDF successfully.");
}
}Merge multiple XPS documents into a single XPS File
Combine disparate XPS packages or generated invoice pages into a single multi-page XPS file.
import com.aspose.page.xps.XpsDocument;
public class MergeXpsFiles {
public static void main(String[] args) throws Exception {
// Open base XPS document
XpsDocument baseDocument = new XpsDocument("C:/Project/Input/document1.xps");
// Define array of additional XPS documents to append
String[] xpsFilesToMerge = new String[] {
"C:/Project/Input/document2.xps",
"C:/Project/Input/document3.xps"
};
// Execute merge operation and save output
baseDocument.merge(xpsFilesToMerge, "C:/Project/Output/merged_document.xps");
baseDocument.close();
System.out.println("XPS documents merged into a single XPS package successfully.");
}
}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.