Java - Merge multiple images to a single PDF using PDFBox -


i able merge multiple pdf files single pdf using code below -

public void mergepdf() {         file file1 = new file("inputpdf/001.pdf");         file file2 = new file("inputpdf/002.pdf");         file file3 = new file("inputpdf/003.pdf");         file file4 = new file("inputpdf/004.pdf");         try {             pddocument doc1 = pddocument.load(file1);             pddocument doc2 = pddocument.load(file2);             pddocument doc3 = pddocument.load(file3);             pddocument doc4 = pddocument.load(file4);             pdfmergerutility pdfmerger = new pdfmergerutility();              pdfmerger.setdestinationfilename("outputimages/merged.pdf");             system.out.println("destination path set "+pdfmerger.getdestinationfilename());             pdfmerger.addsource(file1);             pdfmerger.addsource(file2);             pdfmerger.addsource(file3);             pdfmerger.addsource(file4);                  //merging documents             pdfmerger.mergedocuments();             doc1.close();             doc2.close();             doc3.close();             doc4.close();             system.out.println("done!");                     } catch (ioexception e) {             e.printstacktrace();         }     } 

however, requirement merge multiple images (jpg, png) single pdf well.

is possible merge multiple images single pdf using pdfbox?

you need convert images pdf first. see how can convert png file pdf using java? or create pdf png image or java panel example on how this. after that, use pdfbox merge resulting pdfs.


Comments