كيفية تحويل OTG إلى PDF في C#

في هذا البرنامج التعليمي الإرشادي ، سنوضح لك كيفية تحويل OTG إلى PDF في C#. يمكن تحويل OTG إلى PDF باستخدام تطبيقات C# في بضع خطوات بسيطة وسهلة بمساعدة Aspose.Imaging for .NET.

خطوات تحويل OTG إلى PDF في C#

  1. قم بتثبيت حزمة Aspose.Imaging for .NET NuGet
  2. قم بتضمين مساحات الأسماء Aspose.Imaging و Aspose.Imaging.ImageOptions و Aspose.Imaging.FileFormats.Pdf
  3. حدد الترخيص باستخدام فئة Aspose.Imaging.License
  4. قم بتحميل ملف OTG باستخدام طريقة Image.Load
  5. اضبط خيارات ملف PDF باستخدام فئة PdfOptions
  6. قم بتعيين معلومات البيانات الوصفية لـ PDF باستخدام فئة PdfDocumentInfo
  7. احفظ ملف PDF الناتج باستخدام طريقة الحفظ وخيارات PdfSaveOptions

لاحظ أنه في الخطوتين 5 و 6 أعلاه ، نقوم بتعيين معلومات وخصائص ملف PDF الناتج والذي سيتم تحويله من الإدخال OTG graphics file.

كود لتحويل OTG إلى PDF في C#

using System;
//Add Aspose.Imaging for .NET package reference
//Use following namespaces to convert OTG to PDF format
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.FileFormats.Pdf;
namespace ConvertOTGToPDF
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before converting an OTG graphics template to PDF
//using Aspose.Imaging for .NET
Aspose.Imaging.License AsposeImagingLicense = new Aspose.Imaging.License();
AsposeImagingLicense.SetLicense(@"c:\asposelicense\license.lic");
//Load OTG template to be converted to PDF in a new Image object
Image ConvertOTGGraphicsToPDF = Image.Load("Input_Graphics_Template.otg");
//create PdfOptions instance to set properties for output PDF
PdfOptions PDFSaveOptions = new PdfOptions();
//set output PDF compliance setting
PDFSaveOptions.PdfCoreOptions.PdfCompliance = PdfComplianceVersion.PdfA1a;
//set output PDF resolution settings to 72 dpi horizontal and vertical
PDFSaveOptions.ResolutionSettings = new ResolutionSetting(72, 72);
//specify settings for the meta data of the output PDF file
PdfDocumentInfo PDFMetadataInfo = new PdfDocumentInfo();
PDFMetadataInfo.Author = "Author Name";
PDFMetadataInfo.Keywords = "Convert OTG to PDF, OTG to PDF";
PDFMetadataInfo.Subject = "Convert OTG to PDF in C#";
//set PDF document information to the set metadata
PDFSaveOptions.PdfDocumentInfo = PDFMetadataInfo;
//save converted output PDF file with specified save options
ConvertOTGGraphicsToPDF.Save("PDFConvertedFromOTG.pdf", PDFSaveOptions);
}
}
}

باستخدام المقتطف أعلاه ، يمكنك بسهولة إنشاء محول OTG إلى PDF الخاص بك في كود C# في مشاريع .NET بما في ذلك سطح مكتب Windows أو ASP.NET على الويب أو تطبيقات وحدة التحكم.

 عربي