
package mergedocumentospdf2;

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 MergeDocumentosPDF2 {

    public static void main(String[] args) throws IOException {
        String[] documentos = {"Primero","Segundo","Tercero"};
        PDFMergerUtility pDFMergerUtility = new PDFMergerUtility();
        pDFMergerUtility.setDestinationFileName("D:\\PDFs_creados\\Fusionado.pdf");
        
        for (int i=0; i<documentos.length; i++) {
            File file = new File("D:\\PDFs_creados\\" +documentos[i]+".pdf");
            // PDDocument pDDocument = PDDocument.load(file);     
            pDFMergerUtility.addSource(file);             
        }
        
        pDFMergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
        // pDFMergerUtility.mergeDocuments(MemoryUsageSetting.setupTempFileOnly()); 
    }  
}

