Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Merge JPG files in Java

Merge JPG Online


This Gist provides the details on how to Merge JPG files using Aspose.PDF Cloud SDK for Java.
In order to accomplish this requirement, we are going to first create blank PDF file, add a blank page to PDF file, insert JPEG images into PDF page and then convert it to JPEG format. The JPG images are loaded from local drive and the resultant file is uploaded to cloud storage. For complete details, please visit Merge JPG Images online using Java.

Merge JPG Images online using Java

Important Links

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

Merge JPG files in Java
// for more examples, please visit https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-java
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 PDF document
String name = "input.pdf";
// create a blank PDF document in cloud storage
DocumentResponse document = pdfApi.putCreateDocument(name, "Internal",null);
// page number of PDF file
int pageNumber = 1;
// read image files from local drive
File imageFile1 = new File("c://pdf-to-word-queries.JPG");
File imageFile2 = new File("c://PDF-to-Word-Suggestions.JPG");
File imageFile3 = new File("c://word-to-pdf-suggestions.JPG");
File imageFile4 = new File("c://word-to-pdf-queries.JPG");
// Insert images in first page of PDF at specified coordinates
// The coordinates are in Point starting from Bottom-Left to Top-Right
pdfApi.postInsertImage(name, pageNumber, 10.0, 850.0, 580.0, 650.0, null,"Internal",null,imageFile1);
pdfApi.postInsertImage(name, pageNumber, 10.0, 640.0, 580.0, 440.0, null,"Internal",null,imageFile2);
pdfApi.postInsertImage(name, pageNumber, 10.0, 430.0, 580.0, 230.0, null,"Internal",null,imageFile3);
pdfApi.postInsertImage(name, pageNumber, 10.0, 220.0, 580.0, 10.0, null,"Internal",null,imageFile4);
// call the API to convert PDF page to JPG format
AsposeResponse response =pdfApi.putPageConvertToJpeg(name, pageNumber, "PDFConverted.jpg", 800, 1024, null,"Internal");
// print success message
System.out.println("Combine JPG successful !");
}catch(Exception ex)
{
System.out.println(ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment