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

Sort:  

Congratulations @bijendrachauhan! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published

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

By upvoting this notification, you can help all Steemit users. Learn how here!

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) :

You published 4 posts in one day

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

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @bijendrachauhan! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:

Introducing SteemitBoard Ranking

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @bijendrachauhan! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

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!

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.032
BTC 65955.88
ETH 3055.54
USDT 1.00
SBD 3.69