تحويل PS و EPS و XPS

PS و EPS و XPS Converter API حل لـ .NET.

 

كلما دعت الحاجة إلى تحويل ملفات PostScript PS و Encapsulated PostScript EPS بالإضافة إلى مستندات XPS برمجيًا ، يمكن لـ .NET API القيام بذلك بسلاسة وتحويل ملفات متعددة. بالنسبة إلى PS و EPS ، تدعم API عوامل تشغيل Levels 1-3 PostScript ومعظم تعليقات رأس EPS بالإضافة إلى تحويل مستندات PostScript ذات المطابقة القصوى باستثناء بعض حالات الخطوط وصفقات API مثل الخطوط مثل Time New Roman.

علاوة على ذلك ، بالنسبة لتحويل ملفات XPS ، يمكن لواجهة برمجة التطبيقات إضافة أو إزالة الصفحات ، والتعامل مع اللوحات ، والمسارات وعناصر الحروف الرسومية ، وإنشاء أشكال رسومات متجهة ، وسلاسل نصية ، وتحويل عناصر مخطط XPS والمزيد.

يتيح لك حل API لـ .NET هنا تحويل الملفات من تنسيقات PDL مثل PS و EPS و XPS برمجيًا ، ولكن قد تجد أنه من المفيد رؤية الأنظمة الأساسية التي تم تطويرها على واجهات برمجة التطبيقات الأصلية هذه وتجربتها.

تحويل 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.'

لأي تطبيق EPS / PS PostScript لتحويل الصور ، يعمل كود 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 إلى تنسيقات أخرى عبر الإنترنت أو برمجيًا. إذا كنت بحاجة إلى تحويل ملفاتك فورًا عبر الإنترنت ، فقد ترغب في استخدام تطبيق متعدد الأنظمة الأساسية محول ملفات تنسيق لغة وصف الصفحة .

2. ما هي اللغات التي يدعمها المحول لوصف الصفحة؟

تدعم وظيفة التحويل هذه الملفات ذات الامتدادات .ps و .eps و. xps. يتم تمثيل PDLs الشهيرة مثل PDF و SVG كحلول منفصلة في Aspose.products

3. هل الوظيفة مجانية؟

تعد المحولات متعددة الأنظمة الأساسية مجانية ، عندما يمكنك الحصول على نسخة تجريبية مجانية من حل API ثم شراء المنتج إذا لزم الأمر.

 

تحويل XPS إلى صور JPG و PNG و BMP عبر C# .NET.'

يدعم .NET API أيضًا تحويل XPS إلى صور BMP و JPG و PNG و TIFF وما إلى ذلك ، ويوفر فئة XpsDocument لعمليات XPS. لتحويل XPS إلى صورة ، اتبع الخطوات التالية:

  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);
}
}
 
  

Support and Learning Resources