แปลง PS, EPS และ XPS

โซลูชัน API ตัวแปลง PS, EPS และ XPS สำหรับ .NET

 

เมื่อใดก็ตามที่จำเป็นต้องแปลงไฟล์ PostScript PS และ Encapsulated PostScript EPS ตลอดจนเอกสาร XPS โดยทางโปรแกรม .NET API สามารถทำได้อย่างราบรื่นและแปลงไฟล์หลายไฟล์ สำหรับ PS และ EPS นั้น API รองรับตัวดำเนินการ PostScript ระดับ 1-3 และความคิดเห็นส่วนหัวของ EPS ส่วนใหญ่ รวมถึงการแปลงเอกสาร PostScript ที่มีความสอดคล้องสูงสุด ยกเว้นกรณีแบบอักษรบางตัวและ API เกี่ยวข้องกับแบบอักษรเช่น Time New Roman

นอกจากนี้ สำหรับการแปลงไฟล์ XPS นั้น API สามารถเพิ่มหรือลบหน้า จัดการกับผืนผ้าใบ เส้นทางและองค์ประกอบร่ายมนตร์ สร้างรูปร่างกราฟิกแบบเวกเตอร์ สตริงข้อความ แปลงรายการเค้าร่าง XPS และอื่นๆ

โซลูชัน API สำหรับ .NET ที่นี่ให้คุณแปลงไฟล์รูปแบบ PDL เช่น PS, EPS และ XPS โดยทางโปรแกรม แต่คุณอาจพบว่ามีประโยชน์ในการดูและลองใช้ข้ามแพลตฟอร์มที่พัฒนาบน API ดั้งเดิมเหล่านี้

การแปลง PostScript เป็น PDF ผ่าน C# .NET

ในการแปลงไฟล์ PostScript PS และ Encapsulated PostScript EPS เป็น PDF ผ่าน .NET API คุณต้องทำตามขั้นตอนต่อไป:

  1. โหลดไฟล์ PS หรือ EPS โดยใช้ PsDocument Class
  2. ตั้งค่าการบันทึก PDF โดยใช้ PdfSaveOptions Class
  3. ใช้ FileStream Class สำหรับเอาต์พุตไฟล์ PDF
  4. PdfDevice Class โดยเริ่มต้นด้วยออบเจกต์ไฟล์สตรีม PDF เอาต์พุต
  5. โทร 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 to image converter ของ EPS/PS โค้ด C# ต่อไปนี้ใช้งานได้ดี ดังนั้นให้ทำตามขั้นตอนต่อไป:

  1. โหลดเอกสารโดยใช้คลาส PsDocument ที่มีสตรีมไฟล์อินพุตเป็นพารามิเตอร์
  2. สร้าง ImageSaveOptions Class ออบเจ็กต์และเริ่มต้นใช้งานด้วยการตั้งค่าที่จำเป็น
  3. บันทึกแต่ละหน้าไฟล์อินพุตเป็นรูปภาพ 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 Class สำหรับการดำเนินการ XPS ในการแปลง XPS เป็น Image ให้ทำตามขั้นตอนต่อไปนี้:

  1. โหลดไฟล์ XPS จากสตรีม
  2. เริ่มต้นตัวเลือกการบันทึกรูปภาพที่เกี่ยวข้อง เช่น XPS เป็น JPG คือ JpegSaveOptions และสำหรับ XPS เป็น PNG PngSaveOptions นี่คือรายการของ XPS เป็นอิมเมจทั้งหมด บันทึกตัวเลือก
  3. กำหนดการตั้งค่าที่เกี่ยวข้อง เช่น 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);
}
}