
package mergedocumentospdf;

import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.multipdf.PDFMergerUtility;
import org.apache.pdfbox.pdmodel.PDDocument;

public class MergeDocumentosPDF {

    public static void main(String[] args) throws IOException {

        PDFMergerUtility pDFMergerUtility = new PDFMergerUtility();
        pDFMergerUtility.setDestinationFileName("D:\\PDFs_creados\\Fusionado.pdf");
        
        for (int i=1; i<=3; i++) {
            File file = new File("D:\\PDFs_creados\\Prueba" +Integer.toString(i)+".pdf");
            // PDDocument pDDocument = PDDocument.load(file);     
            pDFMergerUtility.addSource(file);             
        }
        
        pDFMergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
        // pDFMergerUtility.mergeDocuments(MemoryUsageSetting.setupTempFileOnly()); 
    }  
}
