Merging pdf files in Java
import org.apache.pdfbox.multipdf.PDFMergerUtility;
import org.apache.pdfbox.pdmodel.PDDocument;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
public class MergePdf {
public static void main(String[] args) throws IOException {
//Loading an existing PDF document
File file1 = new File("d:/data/1.pdf");
PDDocument doc1 = PDDocument.load(file1);
File file2 = new File("d:/data/2.pdf");
PDDocument doc2 = PDDocument.load(file2);
File file3 = new File("d:/data/3.pdf");
PDDocument doc3 = PDDocument.load(file3);
//Instantiating PDFMergerUtility class
PDFMergerUtility PDFmerger = new PDFMergerUtility();
//Setting the destination file
PDFmerger.setDestinationFileName("d:/data/result2.pdf");
//adding the source files
PDFmerger.addSource(file1);
PDFmerger.addSource(file2);
PDFmerger.addSource(file3);
//Merging the documents
PDFmerger.mergeDocuments();
//Closing the documents
doc1.close();
doc2.close();
doc3.close();
}
}
Posted on Utopian.io - Rewarding Open Source Contributors
Congratulations @bijendrachauhan! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Your contribution cannot be approved because 'blog posts' (or any category) is not suitable for code snippets.
You can contact us on Discord.
[utopian-moderator]
Congratulations @bijendrachauhan! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @bijendrachauhan! You have received a personal award!
Click on the badge to view your Board of Honor.
Do not miss the last post from @steemitboard:
Congratulations @bijendrachauhan! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!