Come convertire OTG in PDF in C#

In questo tutorial, ti mostreremo come convertire OTG in PDF in C#. La conversione di OTG in PDF utilizzando le applicazioni C# può essere eseguita in pochi semplici passaggi con l’aiuto di Aspose.Imaging per .NET.

Passaggi per la conversione di OTG in PDF in C#

  1. Installa Aspose.Imaging for .NET pacchetto NuGet
  2. Includi spazi dei nomi Aspose.Imaging, Aspose.Imaging.ImageOptions e Aspose.Imaging.FileFormats.Pdf
  3. Impostare la licenza Aspose utilizzando la classe Aspose.Imaging.License
  4. Carica il file OTG utilizzando il metodo Image.Load
  5. Imposta le opzioni del file PDF utilizzando la classe PdfOptions
  6. Imposta le informazioni sui metadati PDF utilizzando la classe PdfDocumentInfo
  7. Salva il PDF di output utilizzando il metodo Salva e PdfSaveOptions

Tieni presente che nei passaggi 5 e 6 precedenti, stiamo impostando le informazioni e le proprietà del PDF di output che verrà convertito dall’input OTG graphics file.

Codice per convertire OTG in PDF in 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);
}
}
}

Utilizzando lo snippet sopra, puoi facilmente creare il tuo convertitore da OTG a PDF in codice C# nei tuoi progetti .NET, inclusi desktop Windows, Web ASP.NET o applicazioni console.

 Italiano