PDFBox is providing excellent support for merging multiple PDF files into one. You just need to add following jars in your project and use below code to merge multiple pdfs
1.
import java.io.IOException;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.util.PDFMergerUtility;
public class PDFMerge {
public static void main(String[] args) throws COSVisitorException, IOException {
PDFMergerUtility mergePdf = new PDFMergerUtility();
String folder="D:\\";
String numberOfFiles[]={"a.pdf","b.pdf"};
for(int i = 0; i < numberOfFiles.length; i++){
mergePdf.addSource(folder + numberOfFiles[i]);
}
mergePdf.setDestinationFileName(folder+"merge.pdf");
mergePdf.mergeDocuments();
}
}
1. PDFBox.jar
2. apache-common-logging
Ref:http://java.dzone.com/news/merging-pdf%E2%80%99s-with-pdfbox
No comments:
Post a Comment