Create pdf and merge with pdfbox

后端 未结 4 979
眼角桃花
眼角桃花 2021-02-10 16:03

This is what I want to do:

  1. Make 2 different pdf files using pdfbox

  2. Merge these two files together using pdfmerger

I know how

4条回答
  •  再見小時候
    2021-02-10 16:06

    You can use this way also:-
    1) Create List of InputStream
    2) Instantiate PDFMergerUtility class
    3) Set Destination Output Stream
    4) Add all InputStreams to PDFMerger as Source files which needs to be merged.
    5) Merge the documents by calling "PDFmerger.mergeDocuments();"

       List locations=new ArrayList();
            locations.add(new FileInputStream("E:/Filenet Project Support/MergePDFs_Sample_Code/Attorney_new_form.pdf"));
            locations.add(new FileInputStream("E:/Filenet Project Support/MergePDFs_Sample_Code/JH.pdf"));
            locations.add(new FileInputStream("E:/Filenet Project Support/MergePDFs_Sample_Code/Interpreter_new_form.pdf"));
            //Instantiating PDFMergerUtility class
            PDFMergerUtility PDFmerger = new PDFMergerUtility();
            //Setting Destination Output Stream
            OutputStream out = new FileOutputStream("E:/Filenet Project Support/MergePDFs_Sample_Code/merged.pdf");
            //Adding all InputStreams to PDFMerger as Source files which needs to be merged.
            PDFmerger.addSources(locations);
            //Setting Destination Output Stream
            PDFmerger.setDestinationStream(out);
            //Merging the two documents
            PDFmerger.mergeDocuments();
            System.out.println("Documents merged");
    

提交回复
热议问题