This gist shows code snippet on how to convert JPG to PDF format using Aspose.PDF Cloud SDK for .NET.
For more information, please visit
This gist shows code snippet on how to convert JPG to PDF format using Aspose.PDF Cloud SDK for .NET.
For more information, please visit
// get client credentials from https://dashboard.aspose.cloud/ | |
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 | |
pdfApi.UploadFile(imageFile,file); | |
} | |
// 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) | |
}); | |
try | |
{ | |
// 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 !"); | |
Console.ReadKey(); | |
} | |
} | |
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 |