Merging files with PdfSmartCopy throws a NullPointerException

Andrea <[email protected]>
Newsgroups gmane.comp.java.lib.itext.general
Message-ID <[email protected]>
Hi, I experienced some random NPE when merging documents using iText 5.5.x
and I managed to create a SSCCE. The exception is triggered only when using
PdfSmartCopy AND consolidateNamedDestinations is called on the reader AND
selectPages is called on the reader.
This is the document I used but it happened with others:
http://open-advice.org/Open-Advice.pdf
To keep the example short I didn't include multiple documents.
I think it is probably a bug but please let me know if there is anything
wrong with the code.

 public static void main(String[] args) throws IOException,
DocumentException {
        File outputFile = File.createTempFile("test", ".pdf");
        RandomAccessSource ras = FACTORY
                .createBestSource("/some-path/Open-Advice.pdf");
        PdfReader reader = new PdfReader(new RandomAccessFileOrArray(ras),
null);
        OutputStream outputStream = new FileOutputStream(outputFile);
        Document pdfDocument = new
Document(reader.getPageSizeWithRotation(1));
        PdfSmartCopy pdfCopy = new PdfSmartCopy(pdfDocument, outputStream);
        pdfDocument.open();
        reader.consolidateNamedDestinations();
        reader.selectPages("1-50");
        pdfCopy.addDocument(reader);
        pdfCopy.freeReader(reader);
        pdfCopy.close();
        reader.close();
        outputStream.close();
        System.out.println("created " + outputFile.getAbsolutePath());
    }

and this is the Stacktrace:

Exception in thread "main" java.lang.NullPointerException
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serObject(PdfSmartCopy.java:189)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serArray(PdfSmartCopy.java:237)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serObject(PdfSmartCopy.java:201)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serDic(PdfSmartCopy.java:228)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serObject(PdfSmartCopy.java:198)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serDic(PdfSmartCopy.java:228)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.serObject(PdfSmartCopy.java:198)
	at
com.itextpdf.text.pdf.PdfSmartCopy$ByteStore.<init>(PdfSmartCopy.java:265)
	at com.itextpdf.text.pdf.PdfSmartCopy.copyIndirect(PdfSmartCopy.java:110)
	at com.itextpdf.text.pdf.PdfCopy.copyObject(PdfCopy.java:577)
	at com.itextpdf.text.pdf.PdfCopy.copyArray(PdfCopy.java:550)
	at com.itextpdf.text.pdf.PdfCopy.copyObject(PdfCopy.java:581)
	at com.itextpdf.text.pdf.PdfCopy.copyDictionary(PdfCopy.java:493)
	at com.itextpdf.text.pdf.PdfCopy.copyDictionary(PdfCopy.java:519)
	at com.itextpdf.text.pdf.PdfCopy.addPage(PdfCopy.java:663)
	at com.itextpdf.text.pdf.PdfSmartCopy.addPage(PdfSmartCopy.java:158)
	at com.itextpdf.text.pdf.PdfCopy.addDocument(PdfCopy.java:814)
	at org.pdfsam.ui.TestIText.main(TestIText.java:54)

Regards,
Andrea



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Merging-files-with-PdfSmartCopy-throws-a-NullPointerException-tp4660460.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.