Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Code snippets for converting JPG to PDF using C#
// get client credentials from
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// Create an instance of PdfApi
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
// name of intput JPG file
string imageFile = "word-to-jpg.jpeg";
// name of resultant PDF to be generated on Cloud storage
string resultantFile = "converted.pdf";
// read the image file from local storage
using (var file = System.IO.File.OpenRead("/Users/nshahbaz/Desktop/" + imageFile))
// Upload original document to Cloud Storage
// create an ImageTemplateRequest instance defining properties for output PDF
// We have set margin details for PDF and have enabled the OCR properties
ImageTemplatesRequest imageTemplatesRequest = new ImageTemplatesRequest(IsOCR: true,
OCRLangs: "eng",
ImagesList: new List<ImageTemplate>()
new ImageTemplate(ImagePath: $"word-to-jpg.jpeg", ImageSrcType: ImageSrcType.Common, LeftMargin : 10, RightMargin : 10)
// Invoke SDK to convert JPG to PDF and save output in Cloud storage
var apiResponse = pdfApi.PutImageInStorageToPdf(resultantFile, imageTemplatesRequest);
if (apiResponse != null && apiResponse.Status.Equals("OK"))
Console.WriteLine("JPG successfully converted to PDF !");
catch (Exception ex)
Console.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
Code snippets for converting JPG to PDF using Aspose.PDF Cloud SDK for .NET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment