PDFClown:如何克隆页面

时间:2018-06-29 13:22:44

标签: java pdfclown

我想在pdfclown的帮助下将页面从旧的pdf文件复制到新的文件中。

到目前为止,我已经尝试了以下方法:

    File newFile = new File();
    Document document = newFile.getDocument();
    for (int pageNumber : pageNumbers) {
         document.getPages().add(oldFile.getDocument().getPages().get(pageNumber).clone(document));
    }

    return newFile;

不幸的是,执行clone(document)

时会出现NullPointer
    java.lang.NullPointerException
    at org.pdfclown.files.IndirectObjects.addExternal(IndirectObjects.java:208)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:357)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:367)
    at org.pdfclown.objects.PdfReference.accept(PdfReference.java:94)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:343)
    at org.pdfclown.objects.PdfDictionary.accept(PdfDictionary.java:161)
    at org.pdfclown.files.IndirectObjects.addExternal(IndirectObjects.java:208)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:357)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:367)
    at org.pdfclown.objects.PdfReference.accept(PdfReference.java:94)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:318)
    at org.pdfclown.objects.PdfArray.accept(PdfArray.java:113)
    at org.pdfclown.files.IndirectObjects.addExternal(IndirectObjects.java:208)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:357)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:367)
    at org.pdfclown.objects.PdfReference.accept(PdfReference.java:94)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:343)
    at org.pdfclown.objects.PdfDictionary.accept(PdfDictionary.java:161)
    at org.pdfclown.files.IndirectObjects.addExternal(IndirectObjects.java:208)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:357)
    at org.pdfclown.objects.Cloner.visit(Cloner.java:367)
    at org.pdfclown.objects.PdfReference.accept(PdfReference.java:94)
    at org.pdfclown.objects.PdfObject.clone(PdfObject.java:96)
    at org.pdfclown.objects.PdfReference.clone(PdfReference.java:222)
    at org.pdfclown.objects.PdfReference.clone(PdfReference.java:1)
    at org.pdfclown.objects.PdfObjectWrapper.clone(PdfObjectWrapper.java:159)

0 个答案:

没有答案