Skip to content

Instantly share code, notes, and snippets.

@blog-aspose-cloud
Last active July 30, 2022 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blog-aspose-cloud/9e46aad1be262d5c18e0f7684ca6a441 to your computer and use it in GitHub Desktop.
Save blog-aspose-cloud/9e46aad1be262d5c18e0f7684ca6a441 to your computer and use it in GitHub Desktop.
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 https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-java/tree/master/Examples/src/main/java/com/aspose/asposecloudpdf/examples
try
{
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/
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)
{
System.out.println(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