Example usage for org.apache.pdfbox.multipdf PDFCloneUtility PDFCloneUtility

List of usage examples for org.apache.pdfbox.multipdf PDFCloneUtility PDFCloneUtility

Introduction

In this page you can find the example usage for org.apache.pdfbox.multipdf PDFCloneUtility PDFCloneUtility.

Prototype

PDFCloneUtility(PDDocument dest) 

Source Link

Document

Creates a new instance for the given target document.

Usage

From source file:pdfsplicer.SplicerModel.java

License:Open Source License

/**
 * Create the new PDF, and save it./*ww  w. j a  v  a2 s.  co  m*/
 * 
 * @param saveFile the file to save it as
 * @throws IOException if it cannot save the file
 */
public void makeFinalizedPDF(File saveFile) throws IOException {

    PDDocument doc = null;
    PDDocument newdoc = new PDDocument();

    for (int i = 0; i < pageEntryPDFList.size(); ++i) {
        doc = pdfList.get(pageEntryPDFList.get(i));

        if (doc.isEncrypted()) {
            System.out.println("Error: Encrypted PDF");
            System.exit(1);
        }

        List<Integer> pRange = pageRangeList.get(i);
        PDFCloneUtility pdfCloner = new PDFCloneUtility(newdoc);
        for (int pNum : pRange) {
            PDPage page = doc.getPage(pNum - 1);
            COSDictionary clonedDict = (COSDictionary) pdfCloner.cloneForNewDocument(page);
            newdoc.addPage(new PDPage(clonedDict));
        }
    }

    newdoc.save(saveFile);
    if (newdoc != null) {
        newdoc.close();
    }
}