Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Last active April 17, 2021 00:59
Show Gist options
  • Save conholdate-gists/f256c562ad7f6f9c83a7ae04871ec4c6 to your computer and use it in GitHub Desktop.
Save conholdate-gists/f256c562ad7f6f9c83a7ae04871ec4c6 to your computer and use it in GitHub Desktop.
This Gist contains the code snippet for JPG image to PNG conversion and also, JPEG to PDF conversion using C# .NET

This Gist contains the code snippet for JPEG image to PNG conversion and also, JPEG to PDF conversion using C# .NET. Further details related to code snippet can be found over following blog post

This Gist contains the code snippet for JPG image to PNG conversion and also, JPEG to PDF conversion using C# .NET
// create an object to initiate the license
Aspose.Imaging.License license = new Aspose.Imaging.License();
// provide path of license file
license.SetLicense("/Documents/Conholdate.Total.NET.lic");
// Load an existing image (of type JPEG ) in an instance of the Image class
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dataDir+"samsung_galaxy.jpg"))
{
// create an instance of PdfOptions class
Aspose.Imaging.ImageOptions.PdfOptions pdfOptions = new Aspose.Imaging.ImageOptions.PdfOptions();
// create PdfDocumentInfo object and pass it to PdfOptions instance
pdfOptions.PdfDocumentInfo = new Aspose.Imaging.FileFormats.Pdf.PdfDocumentInfo
{
// set author name for the resultant file
Author = "Nayyer Shahbaz",
Title = "JPEG converted to PDF",
Subject = "Aspose.Imaging for .NET"
};
// set the PDF compliance as PDF/A-1a
pdfOptions.PdfCoreOptions = new Aspose.Imaging.FileFormats.Pdf.PdfCoreOptions()
{
PdfCompliance = Aspose.Imaging.PdfComplianceVersion.PdfA1b
};
// save the resultant PDF document
image.Save(dataDir + "_output.pdf", pdfOptions);
}
// create an object to initiate the license
Aspose.Imaging.License license = new Aspose.Imaging.License();
// provide path of license file
license.SetLicense("/Documents/Conholdate.Total.NET.lic");
// Load an existing image (of type JPEG) in an instance of the Image class
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load("/Documents/samsung_galaxy.jpg"))
{
// create an object of PngOptions class
Aspose.Imaging.ImageOptions.PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
// save resultant image and pass PngOptions as argument
image.Save(dataDir + "_output.png", options);
}
// create PngOptions object
Aspose.Imaging.ImageOptions.PngOptions options = new Aspose.Imaging.ImageOptions.PngOptions();
// set color type of resultant image as grayScale
options.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.Grayscale;
// set the compression level for resultant file as 4
options.CompressionLevel = 4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment