การผสานเอกสาร EPS, PostScript (PS) และ XPS ใน Java
ผสานไฟล์ EPS, PostScript (PS) และ XPS หลายไฟล์ให้เป็นเอกสาร PDF แบบหลายหน้าฉบับเดียวโดยใช้ Aspose.Page for Java ผ่านการเขียนโปรแกรม รวมกราฟิกเวกเตอร์แต่ละรายการ ไฟล์สำหรับพิมพ์ หรือสตรีมหน้าเอกสารระหว่างรูปแบบเอกสารต่าง ๆ ได้อย่างราบรื่น โดยไม่ต้องพึ่งพา Adobe Acrobat, Distiller หรือยูทิลิตีการพิมพ์ดั้งเดิมของ Windows
Aspose.Page for Java มีอุปกรณ์เรนเดอร์เฉพาะทาง (PdfDevice, ImageDevice) และตัวเลือกการบันทึกสำหรับแปลงและรวมไฟล์อินพุตหลายไฟล์ให้เป็นเอาต์พุตสตรีมเดียวที่เป็นหนึ่งเดียว
- หากต้องการรวมกราฟิกเวกเตอร์ที่แยกจากกันและภาพประกอบ EPS ให้เป็นพอร์ตโฟลิโอ PDF ที่รวมเป็นหนึ่งเดียว ให้ใช้เมธอด
PsDocument.mergeToPdf() - หากต้องการรวมงานพิมพ์และรายงาน PostScript ที่ประกอบด้วยหลายไฟล์ให้เป็นไฟล์ PDF เดียวที่สามารถพิมพ์ได้ ให้ใช้เมธอด
PsDocument.mergeToPdf() - หากต้องการรวมไฟล์ XPS ใบแจ้งหนี้ หรือเอาต์พุตหน้าจำนวนมากที่แตกต่างกันให้เป็นแพ็กเกจ XPS หรือ PDF เดียว ให้ใช้เมธอด
XpsDocument.merge()
ผสานไฟล์ EPS หลายไฟล์เป็น PDF เดียว
ผสานอาร์เรย์ของไฟล์กราฟิกเวกเตอร์ EPS แยกกันให้เป็นเอกสาร PDF แบบหลายหน้าฉบับเดียว
// 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());
}
}ผสานเอกสาร PostScript (PS) หลายฉบับเป็น PDF เดียว
รวมไฟล์ PostScript แบบหลายหน้าหลายไฟล์ให้เป็นสตรีม PDF ที่รวมเป็นหนึ่งเดียว โดยใช้เส้นทางและตัวเลือกการค้นหาฟอนต์ที่กำหนดเอง
// 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());
}
}ผสานเอกสาร XPS หลายฉบับเป็นไฟล์ XPS เดียว
รวมแพ็กเกจ XPS ที่แตกต่างกันหรือหน้าของใบแจ้งหนี้ที่สร้างขึ้นให้เป็นไฟล์ XPS แบบหลายหน้าไฟล์เดียว
// 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");การติดตั้งและการตั้งค่า
เพิ่ม Aspose.Page for Java ลงใน 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. ฉันสามารถรวมเอกสาร XPS เป็น PDF โดยตรงแทน XPS ได้หรือไม่?
ได้ คุณสามารถโหลดเอกสาร XPS โดยใช้ XpsDocument และเรนเดอร์พร้อมกับไฟล์รองโดยใช้ PdfDevice เพื่อสร้างไฟล์ PDF ที่รวมแล้วโดยตรงจากอินพุต XPS
2. Aspose.Page จัดการกับฟอนต์ที่ขาดหายไปเมื่อรวมไฟล์ PS หรือ EPS อย่างไร?
หากมีการอ้างอิงฟอนต์แบบกำหนดเองในไฟล์ EPS/PS อินพุต คุณสามารถระบุตำแหน่งของฟอนต์เหล่านั้นโดยใช้ PdfSaveOptions.setAdditionalFontsFolders() หากฟอนต์ขาดหายไป Aspose.Page จะใช้ตรรกะการแทนที่ฟอนต์เริ่มต้นที่มีอยู่ภายในเพื่อดำเนินการเรนเดอร์ให้เสร็จสมบูรณ์โดยไม่ทำให้เกิดข้อยกเว้นร้ายแรง
3. ประสิทธิภาพด้านหน่วยความจำยังคงมีประสิทธิภาพหรือไม่เมื่อประมวลผลไฟล์จำนวนมากเป็นชุด?
ได้ Aspose.Page ประมวลผลสตรีมหน้าขาเข้าแบบต่อเนื่องระหว่างการทำงานของอุปกรณ์ PDF ทำให้งานพิมพ์ระดับองค์กรขนาดใหญ่สามารถรวมกันได้อย่างมีประสิทธิภาพโดยใช้หน่วยความจำในระดับต่ำ