แปลง PS, EPS และ XPS
การแปลง PS, EPS และ XPS ด้วยโซลูชัน API สำหรับ .NET
เมื่อใดก็ตามที่มีความจำเป็นต้องแปลงไฟล์ PostScript PS และ Encapsulated PostScript EPS และเอกสาร XPS ด้วยโปรแกรม .NET API สามารถทำได้อย่างราบรื่นและแปลงไฟล์ได้หลายไฟล์ สำหรับ PS และ EPS นั้น API รองรับตัวดำเนินการ PostScript ระดับ 1-3 และความคิดเห็นส่วนหัวของ EPS ส่วนใหญ่ รวมถึงแปลงเอกสาร PostScript โดยมีความสอดคล้องสูงสุด ยกเว้นในกรณีของฟอนต์บางประเภท และ API จะจัดการกับฟอนต์ เช่น Times New Roman
ยิ่งไปกว่านั้น สำหรับการแปลงไฟล์ XPS นั้น API สามารถเพิ่มหรือลบหน้า จัดการกับแคนวาส เส้นทาง และองค์ประกอบกริฟ (glyph) สร้างรูปทรงกราฟิกแบบเวกเตอร์ และสตริงข้อความ แปลงรายการเค้าร่างของ XPS และอื่นๆ อีกมากมาย
โซลูชัน API สำหรับ .NET ที่นี่ช่วยให้คุณแปลงไฟล์รูปแบบ PDL เช่น PS, EPS และ XPS ด้วยโปรแกรม แต่อาจเป็นประโยชน์สำหรับคุณที่จะได้เห็นและลองใช้แอปพลิเคชันข้ามแพลตฟอร์มที่พัฒนาบน API ดั้งเดิมเหล่านี้
การแปลง PostScript เป็น PDF ผ่าน C# .NET
ในการแปลงไฟล์ PostScript PS และ Encapsulated PostScript EPS เป็น PDF ผ่าน .NET API คุณต้องทำตามขั้นตอนต่อไปนี้:
- โหลดไฟล์ PS หรือ EPS โดยใช้ คลาส PsDocument
- ตั้งค่าการบันทึก PDF โดยใช้ คลาส PdfSaveOptions
- ใช้ คลาส FileStream สำหรับไฟล์ PDF เอาต์พุต
- คลาส PdfDevice โดยการกำหนดค่าเริ่มต้นด้วยออบเจกต์สตรีมไฟล์ PDF เอาต์พุต
- เรียกใช้ PsDocument.Save สำหรับการแปลงเป็น PDF
โค้ด C# สำหรับการแปลง PS EPS เป็น PDF
// The path to the documents directory.
string dataDir = "definedDirectoryPath";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(dataDir + "input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool 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.AdditionalFontsFolders = 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, Aspose.Page.Drawing.Size(595x842));
// or
//saveOptions.Size = new Aspose.Page.Drawing.Size(595x842);
document.SaveAsPdf(dataDir + "outputPDF_out.pdf", options);
//Review errors
if (suppressErrors)
{
foreach (Exception ex in options.Exceptions)
{
Console.WriteLine(ex.Message);
}
}การแปลง PostScript เป็นรูปภาพผ่าน C# .NET
สำหรับแอปพลิเคชันตัวแปลง PostScript EPS/PS เป็นรูปภาพ โค้ด C# ต่อไปนี้ทำงานได้ดี ดังนั้นให้ทำตามขั้นตอนต่อไปนี้:
- โหลดเอกสารโดยใช้คลาส PsDocument โดยมีสตรีมไฟล์อินพุตเป็นพารามิเตอร์
- สร้างออบเจกต์ คลาส ImageSaveOptions และกำหนดค่าเริ่มต้นด้วยการตั้งค่าที่จำเป็น
- บันทึกแต่ละหน้าของไฟล์อินพุตเป็นรูปภาพ PNG, JPG, TIFF, BMP และอื่นๆ
โค้ด C# สำหรับการแปลง PostScript เป็นรูปภาพ
// The path to the documents directory.
string dataDir = "definedDirectoryPath";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(dataDir + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.ImageFormat = Aspose.Page.Drawing.Imaging.ImageFormat.Png;
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" };
// Save PS document as array of image bytes, one bytes array for one page.
byte[][] imagesBytes = document.SaveAsImage(options);
//Save images bytes arrays as image files.
int i = 0;
foreach (byte[] imageBytes in imagesBytes)
{
string imagePath = Path.GetFullPath(dataDir + "out_image" + i.ToString() +"." + options.ImageFormat.ToString().ToLower());
using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write))
{
fs.Write(imageBytes, 0, imageBytes.Length);
}
i++;
}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 เป็นรูปภาพ JPG, PNG, BMP ผ่าน C# .NET
.NET API ยังรองรับการแปลง XPS เป็นรูปภาพ BMP, JPG, PNG, TIFF ฯลฯ และมีคลาส XpsDocument สำหรับการทำงานกับ XPS ในการแปลง XPS เป็นรูปภาพ ให้ทำตามขั้นตอนต่อไปนี้:
- โหลดไฟล์ XPS จากสตรีม
- กำหนดค่าตัวเลือกการบันทึกรูปภาพที่เกี่ยวข้อง เช่น สำหรับ XPS เป็น JPG คือ JpegSaveOptions และสำหรับ XPS เป็น PNG คือ PngSaveOptions นี่คือรายการของ ตัวเลือกการบันทึก XPS เป็นรูปภาพทั้งหมด
- กำหนดการตั้งค่าที่เกี่ยวข้อง เช่น SmoothingMode, Resolution และ PageNumbers ฯลฯ สำหรับการเรนเดอร์ สุดท้ายให้ทำซ้ำผ่านพาร์ทิชันเอกสารเพื่อบันทึกเป็นรูปภาพ
โค้ด C# สำหรับการแปลง XPS เป็นรูปภาพ
// The path to the documents directory.
string dataDir = "definedDirectoryPath";
//Outut file
string outputFileName = dataDir + "XPStoImage_out.jpeg";
// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(dataDir + "input.xps", new XpsLoadOptions());
// Initialize options object with necessary parameters.
JpegSaveOptions options = new JpegSaveOptions()
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
Resolution = 300,
PageNumbers = new int[] { 1, 2, 6 }
};
// Save XPS document to the images byte arrays. The first dimension is for inner documents
/// and the second one is for pages within inner documents.
byte[][][] imagesBytes = document.SaveAsImage(options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int i = 0; i < imagesBytes.Length; i++)
{
// Iterate through partition pages
for (int j = 0; j < imagesBytes[i].Length; j++)
{
// Initialize image output stream
using (Stream imageStream = System.IO.File.Open(Path.GetDirectoryName(outputFileName) + Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) +
Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write))
// Write image
imageStream.Write(imagesBytes[i][j], 0, imagesBytes[i][j].Length);
}
}Support and Learning Resources
- แหล่งเรียนรู้
- เอกสาร
- รหัสแหล่งที่มา
- การอ้างอิง API
- การสนับสนุนผลิตภัณฑ์
- การสนับสนุนฟรี
- การสนับสนุนแบบชำระเงิน
- บล็อก
- Release Notes
- ทำไมต้อง Aspose.Page สำหรับ .NET?
- รายชื่อลูกค้า
- เรื่องราวความสำเร็จ