Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JPG to PDF in Java

JPG to PDF online

This Gist provides the details on how to convert JPG to PDF using Aspose.PDF Cloud SDK for Java.
In following code snippet, we need to first create a blank PDF in Cloud storage, load JPG image form local drive and place it inside the newly generate PDF document. The resultant file can be downloaded from linked cloud storage. For complete details, please visit Convert JPG to PDF in Java.

JPG to PDF Online

Important Links

Product Page | Docs | Live Demo | Swagger UI | Code Samples | Source Code | New Releases | Blog | Free Support | Free Trial

// for more examples, please visit
// Get ClientID and ClientSecret from
String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e";
String clientSecret = "1c9379bb7d701c26cc87e741a29987bb";
// create an instance of PdfApi
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// name of input JPG image
String imageFile = "Compare-Word-Document-preview.jpg";
String resultantPDF = "Resultant.pdf";
// create a blank PDF document in cloud storage
DocumentResponse document = pdfApi.putCreateDocument(resultantPDF, "Internal",null);
// load JPG image from local drive
File file = new File("c://Downloads/"+imageFile);
// page number of PDF file
int pageNumber = 1;
// coordinates for image in PDF document
// The coordinates are in Point starting from Bottom-Left to Top-Right
double llx = 10.0;
double lly = 850;
double urx = 580.0;
double ury = 650.0;
// name The document name. (required)
// pageNumber The page number. (required)
// llx Coordinate lower left X. (required)
// lly Coordinate lower left Y. (required)
// urx Coordinate upper right X. (required)
// ury Coordinate upper right Y. (required)
// imageFilePath Path to image file if specified. Request content is used otherwise. (optional)
// storage The document storage. (optional)
// folder The document folder. (optional)
// image Image file. (optional)
pdfApi.postInsertImage(resultantPDF, pageNumber, llx, lly, urx, ury, null,"Internal",null,file);
System.out.println("JPG to PDF Conversion sucessfull !");
}catch(Exception ex)
JPG to PDF using Java Cloud SDK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment