[ 
https://issues.apache.org/jira/browse/PDFBOX-2546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15434672#comment-15434672
 ] 

Miklos Krivan commented on PDFBOX-2546:
---------------------------------------

The problem still exists in version 2.0.2 see my small example below:

{quote}
Caused by: java.lang.IllegalArgumentException: resourceDictionary is null
        at org.apache.pdfbox.pdmodel.PDResources.<init>(PDResources.java:70)
        at 
org.apache.pdfbox.multipdf.PDFMergerUtility.appendDocument(PDFMergerUtility.java:559)
        at 
org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:261)
{quote}

{code:java}
    // T is my document object type
    public <T> ByteArrayOutputStream createDocumentStream(List<T> documents) {
        PDFMergerUtility mergedDoc = new PDFMergerUtility();
        ByteArrayOutputStream mergedOutputstream = new ByteArrayOutputStream();

        for (T doc : documents) {
            ByteArrayOutputStream baos = createDocumentStream(doc);
            // I use Apache FOP 2.1 to generate PDF document

            // when odd number of pages exists I want to add one new empty page
            try (PDDocument currentDoc = PDDocument.load(new 
ByteArrayInputStream(baos.toByteArray()),
                    MemoryUsageSetting.setupMainMemoryOnly())) {
                int numberOfPages = currentDoc.getNumberOfPages();
                if (numberOfPages % 2 == 1) { // when odd number of pages
                    PDPage lastPage = currentDoc.getPage(numberOfPages - 1);
                    PDPage emptyPage = new PDPage(lastPage.getMediaBox());

                    emptyPage.setResources(lastPage.getResources());
                    // without the above line IllegalArgumentException: 
resourceDictionary is null raised
                    // at mergeDocuments method call below

                    currentDoc.addPage(emptyPage);
                    baos.reset();
                    currentDoc.save(baos);
                }
            }

            mergedDoc.addSource(new ByteArrayInputStream(baos.toByteArray()));
        }

        mergedDoc.setDestinationStream(mergedOutputstream);
        mergedDoc.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
        return mergedOutputstream;
    }
{code}


> IllegalArgumentException: resourceDictionary is null in PDFMerger
> -----------------------------------------------------------------
>
>                 Key: PDFBOX-2546
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2546
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.0
>            Reporter: Tilman Hausherr
>            Assignee: John Hewson
>             Fix For: 2.0.0
>
>
> This was first mentioned on the user mailing list by [~giladd]:
> When merging the PDF 1.7 spec with another PDF file this exception appears:
> {code}
> Exception in thread "main" java.lang.IllegalArgumentException: 
> resourceDictionary is null
>       at org.apache.pdfbox.pdmodel.PDResources.<init>(PDResources.java:68)
>       at 
> org.apache.pdfbox.util.PDFMergerUtility.appendDocument(PDFMergerUtility.java:448)
>       at 
> org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:190)
>       at org.apache.pdfbox.tools.PDFMerger.merge(PDFMerger.java:70)
>       at org.apache.pdfbox.tools.PDFMerger.main(PDFMerger.java:46)
>       at org.apache.pdfbox.tools.PDFBox.main(PDFBox.java:76)
> {code}
> I did some debugging, it happens on the very first page. The resources is 
> indeed null, but it exists when viewing with PDFDebugger. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to