U ovom vodiču s uputama, pokazat ćemo vam kako pretvoriti OTG u PDF u C#. Pretvaranje OTG u PDF pomoću C# aplikacija može se izvršiti u samo nekoliko jednostavnih koraka uz pomoć Aspose.Imaging za .NET.
Koraci za pretvaranje OTG u PDF u C#
- Instalirajte Aspose.Imaging for .NET NuGet paket
- Uključi Aspose.Imaging, Aspose.Imaging.ImageOptions i Aspose.Imaging.FileFormats.Pdf prostore imena
- Postavite licencu za Aspose pomoću klase Aspose.Imaging.License
- Učitaj OTG datoteku koristeći Image.Load metodu
- Postavite opcije PDF datoteke pomoću klase PdfOptions
- Postavite PDF metapodatke pomoću klase PdfDocumentInfo
- Spremite izlazni PDF pomoću metode Spremi i PdfSaveOptions
Imajte na umu da u gornjim koracima 5 i 6 postavljamo informacije i svojstva izlaznog PDF-a koji će se pretvoriti iz ulaza OTG graphics file.
Kod za pretvaranje OTG u PDF u 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); | |
} | |
} | |
} |
Pomoću gornjeg isječka možete jednostavno stvoriti vlastiti pretvarač OTG u PDF u C# kodu u svojim .NET projektima uključujući Windows desktop, ASP.NET web ili konzolne aplikacije.