แปลง PS, EPS และ XPS
โซลูชัน API ตัวแปลง PS, EPS และ XPS สำหรับ Java
เมื่อใดก็ตามที่มีความจำเป็นต้องแปลงไฟล์ PostScript PS และ Encapsulated PostScript EPS รวมถึงเอกสาร XPS ด้วยโปรแกรม Java API สามารถทำได้อย่างราบรื่นและแปลงไฟล์ได้หลายไฟล์ สำหรับ PS และ EPS นั้น API รองรับตัวดำเนินการ PostScript ระดับ 1-3 และความคิดเห็นส่วนหัว EPS ส่วนใหญ่ รวมถึงการแปลงเอกสาร PostScript โดยมีความสอดคล้องสูงสุด ยกเว้นในกรณีของฟอนต์บางกรณี ซึ่ง API จะจัดการฟอนต์ดังกล่าวเหมือนกับ Time New Roman
นอกจากนี้ สำหรับการแปลงไฟล์ XPS นั้น API สามารถเพิ่มหรือลบหน้า จัดการองค์ประกอบแคนวาส (canvases), เส้นทาง (paths) และไกลฟ์ (glyphs), สร้างรูปทรงกราฟิกแบบเวกเตอร์ และสตริงข้อความ, แปลงรายการเอาต์ไลน์ของ XPS และอื่นๆ
โซลูชัน API สำหรับ Java ที่นี่ช่วยให้คุณแปลงไฟล์รูปแบบ PDL เช่น PS, EPS และ XPS ด้วยโปรแกรมได้ แต่คุณอาจพบว่ามีประโยชน์ที่จะลองใช้เครื่องมือข้ามแพลตฟอร์มที่พัฒนาขึ้นบน API ดั้งเดิมเหล่านี้
การแปลง PostScript เป็น PDF ผ่าน Java
ในการแปลงไฟล์ PostScript PS และ Encapsulated PostScript EPS เป็น PDF ผ่าน Java API คุณต้องทำตามขั้นตอนต่อไปนี้:
- โหลดไฟล์ PS หรือ EPS โดยใช้คลาส PsDocument
- สร้างออบเจ็กต์ PdfSaveOptions และตั้งค่าตัวเลือกการแปลงที่คุณต้องการ
- เรียก PsDocument.saveAsPdf() พร้อมพาธของไฟล์ผลลัพธ์และออบเจ็กต์ตัวเลือก
โค้ด Java สำหรับแปลง PS EPS เป็น PDF
// Convert PS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "input.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 PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, java.awt.Dimension(595x842));
// or
//saveOptions.setSize(new java.awt.Dimension(595x842));
//If PostScript file contains some graphics written as Type3 font glyphs, but it is not actual glyphs
//the resulting PDF may be incorrect because of default value of options.ConvertFontsToTTF = true
//Try to set this
//options.setConvertFontsToTTF(false);
// Save document as PDF
document.saveAsPdf(getOutputDir() + "outputPDF_out.pdf", options);
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}การแปลง PostScript เป็นรูปภาพผ่าน Java
สำหรับแอปพลิเคชันตัวแปลง PostScript EPS/PS เป็นรูปภาพใดๆ โค้ด Java ต่อไปนี้ทำงานได้ดี ดังนั้นให้ทำตามขั้นตอนต่อไปนี้:
- โหลดไฟล์ PS หรือ EPS โดยใช้คลาส PsDocument
- สร้างออบเจ็กต์ ImageSaveOptions สำหรับรูปแบบรูปภาพปลายทาง
- เรียก PsDocument.saveAsImage() พร้อมออบเจ็กต์ตัวเลือก โฟลเดอร์ผลลัพธ์ และชื่อไฟล์
โค้ด Java สำหรับการแปลง PostScript เป็นรูปภาพ
// Convert PS file to PNG image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.png";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.PNG);
// 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}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}แปลง XPS เป็นรูปภาพ JPG, PNG, BMP ผ่าน Java
Java API จัดการรูปแบบ XPS ที่ใช้สำหรับการแสดงเค้าโครงหน้า ในทุกสถานการณ์ เมื่อใดก็ตามที่มีความจำเป็นต้องแปลง XPS เป็นรูปภาพ BMP, JPG, PNG และ TIFF ด้วยโปรแกรม โค้ดต่อไปนี้สามารถรวมเข้ากับแอปพลิเคชัน Java ได้อย่างง่ายดาย
- โหลดเอกสาร XPS โดยใช้คลาส XpsDocument
- สร้างคลาสตัวเลือกการบันทึกสำหรับรูปแบบปลายทาง — PngSaveOptions , JpegSaveOptions , BmpSaveOptions หรือ TiffSaveOptions
- เรียก XpsDocument.saveAsImage() พร้อมออบเจ็กต์ตัวเลือก โฟลเดอร์ผลลัพธ์ และชื่อไฟล์
โค้ด Java สำหรับการแปลง XPS เป็นรูปภาพ
// Convert XPS file to PNG image.
// Learn more: https://docs.aspose.com/page/java/convert-xps/
//Outut file
String outputFileName = "XPStoPNG_out.png";
// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(getDataDir() + "input.xps");
// Initialize options object with necessary parameters.
PngSaveOptions options = new PngSaveOptions();
options.setSmoothingMode(SmoothingMode.HighQuality);
options.setResolution(300);
options.setPageNumbers(new int[] { 1, 2, 6 });
// Save XPS document to the PNG image files.
document.saveAsImage(options, getOutputDir(), outputFileName);FAQ
1. ฉันสามารถแปลง Postscript ด้วยโซลูชัน API นี้ได้หรือไม่
Aspose.Page มีฟังก์ชันที่ช่วยให้คุณแปลงไฟล์ PS, XPS และ EPS เป็นรูปแบบอื่นทางออนไลน์หรือโดยทางโปรแกรม หากคุณต้องการแปลงไฟล์ออนไลน์ทันที คุณอาจต้องการใช้ Page Description Language format files Converter แอปพลิเคชันข้ามแพลตฟอร์ม
2. ตัวแปลงภาษาใดที่คำอธิบายเพจรองรับ?
ฟังก์ชันการแปลงนี้สนับสนุนไฟล์ที่มีนามสกุล .ps, .eps และ .xps PDL ที่มีชื่อเสียงเช่น PDF และ SVG จะแสดงเป็นโซลูชันแยกต่างหากใน Aspose.products
3. ฟังก์ชั่นฟรีหรือไม่?
ตัวแปลงข้ามแพลตฟอร์ม นั้นฟรี เมื่อสำหรับโซลูชัน API คุณสามารถทดลองใช้งานฟรีแล้วซื้อผลิตภัณฑ์หากจำเป็น
แปลง XPS เป็น PDF ผ่าน Java
กระบวนการแปลงเอกสาร XPS เป็น PDF ด้วยโปรแกรมนั้นง่ายดาย พร้อมผลลัพธ์ที่มีความเที่ยงตรงสูงระหว่างไฟล์อินพุตและเอาต์พุต
- โหลดไฟล์ XPS โดยใช้คลาส XpsDocument
- สร้างออบเจ็กต์ PdfSaveOptions
- เรียก XpsDocument.saveAsPdf() พร้อมพาธของไฟล์ผลลัพธ์และออบเจ็กต์ตัวเลือก
โค้ด Java สำหรับการแปลง XPS เป็น PDF
// Convert XPS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-xps/
// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(getDataDir() + "input.xps");
// Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
options.setTextCompression(PdfTextCompression.Flate);
options.setPageNumbers(new int[] { 1, 2, 6 });
// Save document as PDF
document.saveAsPdf(getOutputDir() + "XPStoPDF_out.pdf", options);Support and Learning Resources
- แหล่งเรียนรู้
- เอกสาร
- รหัสแหล่งที่มา
- การอ้างอิง API
- การสนับสนุนผลิตภัณฑ์
- การสนับสนุนฟรี
- การสนับสนุนแบบชำระเงิน
- บล็อก
- Release Notes
- ทำไมต้อง Aspose.Page สำหรับ Java
- รายชื่อลูกค้า
- เรื่องราวความสำเร็จ