简体   繁体   中英

Unable to open PDF with itext 7.0.0 due to NullPointerException thrown by PdfDocument

When I attempt to open the pdf at this link, http://www.health.state.mn.us/divs/hpsc/hep/merc/ctfapp2015b.pdf , using itext, I get a NullPointerException with the following stacktrace:

NullPointerException   com.itextpdf.kernel.pdf.tagging.ParentTreeHandler.registerMcr (ParentTreeHandler.java:154)
java.lang.NullPointerException
    at com.itextpdf.kernel.pdf.tagging.ParentTreeHandler.registerMcr(ParentTreeHandler.java:154)
    at com.itextpdf.kernel.pdf.tagging.ParentTreeHandler.registerAllMcrs(ParentTreeHandler.java:246)
    at com.itextpdf.kernel.pdf.tagging.ParentTreeHandler.<init>(ParentTreeHandler.java:101)
    at com.itextpdf.kernel.pdf.tagging.PdfStructTreeRoot.<init>(PdfStructTreeRoot.java:78)
    at com.itextpdf.kernel.pdf.PdfDocument.open(PdfDocument.java:1299)
    at com.itextpdf.kernel.pdf.PdfDocument.<init>(PdfDocument.java:199)

My code is very simple:

(new PdfDocument(new PdfReader "blah.pdf"));

Is there something amiss with this PDF? Are there some type(s) of flags I need to pass to be able to open it?

EDIT: This occurs when using iText 7.0.0.

Your document has a corrupt structure tree, or tag tree. You can also check what Acrobat (or any other PDF viewer) shows when you open tags. When you click on a tag, the reader cannot find the content corresponding to that tag.

I don't think you will be able to open this document without exception in iText 7.0.0, but this issue is already fixed (now only logger errors are printed and no exception thrown), and the fix will be available in 7.0.1. Or you can check out the current snapshot version if you need the fix sooner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM