تحويل XPS إلى .NET
إدخال XPS Converter for .NET
XPS Converter for .NET هو مكتبة قوية تتيح للمطورين تحويل ملفات xPS (مواصفات الورق XML) إلى تنسيقات صورة مختلفة، بما في ذلك PNG، JPEG، TIFF، وأكثر من ذلك.
تحويل XPS إلى PDF
تحويل ملف XPS هو عملية بسيطة تنطوي على تحميل ملفات xPS وتحديد تنسيق الإخراج.المثال التالي للرمز يظهر كيفية التحويل من ملفة xps إلى وثيقة PDF:
XpsConverter converter = new XpsConverter();
XpsConverterToPdfOptions opt = new XpsConverterToPdfOptions();
opt.AddDataSource(new FileDataSource("input.xps"));
opt.AddSaveDataSource(new FileDataSource("output.pdf"));
converter.Process(opt);
In this example, we load the XPS file from a stream and create a new XpsConverter
object. We then specify the output format as PDF and save the document to a new stream.
تحويل XPS إلى صور
تحويل ملف XPS هو عملية بسيطة تنطوي على تحميل الملف xPS وتحديد تنسيق الإخراج.المثال التالي للرمز يظهر كيفية التحويل من ملفات xps إلى صورة PNG:
XpsConverter converter = new XpsConverter();
PsConverterToImageOptions opt = new PsConverterToImageOptions();
opt.AddDataSource(new FileDataSource("input.xps"));
opt.AddSaveDataSource(new FileDataSource("output.png"));
converter.Process(opt);
In this example, we load the XPS file from a stream and create a new XpsConverter
object. We then specify the output format as PNG and save the document to a new stream.
تنسيقات الخروج المدعومة
يدعم XPS Converter for .NET مجموعة واسعة من تنسيقات الإنتاج، بما في ذلك:
- رسومات الشبكة المحمولة (Portable Network Graphics)
- JPEG (مجموعة خبراء التصوير الفوتوغرافي المشترك)
- TIFF (تصميم ملف الصورة المسمى)
- بطاقة BMP (Bitmap)
- GIF (فرم تبادل الرسومات)
التعامل مع الأخطاء والاستثناءات
يلقي XPS Converter for .NET استثناءات إذا حدث خطأ أثناء عملية التحويل.
try
{
XpsConverter converter = new XpsConverter();
XpsConverterToPdfOptions opt = new XpsConverterToPdfOptions();
opt.AddDataSource(new FileDataSource("input.xps"));
opt.AddSaveDataSource(new FileDataSource("output.pdf"));
converter.Process(opt);
}
catch (NotSupportedException ex)
{
Console.WriteLine($"Error converting file: {ex.Message}");
}
Note that the NotSupportedException
class provides additional information about the error, such as the error code and message.