We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello, reading a pdf file the library rises the following exception:
class com.lowagie.text.pdf.PdfDictionary cannot be cast to class com.lowagie.text.pdf.PRIndirectReference
I temporary solved the issue by adding to the PdfReader class the method:
private void iteratePages(PRIndirectReference rpage) { PdfDictionary page = (PdfDictionary) getPdfObject(rpage); PdfArray kidsPR = page.getAsArray(PdfName.KIDS); // reference to a leaf if (kidsPR == null) { page.put(PdfName.TYPE, PdfName.PAGE); PdfDictionary dic = pageInh.get(pageInh.size() - 1); PdfName key; for (Object o : dic.getKeys()) { key = (PdfName) o; if (page.get(key) == null) page.put(key, dic.get(key)); } if (page.get(PdfName.MEDIABOX) == null) { PdfArray arr = new PdfArray(new float[] { 0, 0, PageSize.LETTER.getRight(), PageSize.LETTER.getTop() }); page.put(PdfName.MEDIABOX, arr); } refsn.add(rpage); } // reference to a branch else { page.put(PdfName.TYPE, PdfName.PAGES); pushPageAttributes(page); for (int k = 0; k < kidsPR.size(); ++k) { PdfObject obj = kidsPR.getPdfObject(k); if (!obj.isIndirect()) { while (k < kidsPR.size()) kidsPR.remove(k); break; } if (obj instanceof PRIndirectReference) iteratePages((PRIndirectReference) obj); else if (obj instanceof PdfDictionary) iteratePages((PdfDictionary) obj); } popPageAttributes(); } } private void iteratePages(PdfDictionary page) { PdfArray kidsPR = page.getAsArray(PdfName.KIDS); // reference to a leaf if (kidsPR != null) { page.put(PdfName.TYPE, PdfName.PAGES); pushPageAttributes(page); for (int k = 0; k < kidsPR.size(); ++k) { PdfObject obj = kidsPR.getPdfObject(k); if (!obj.isIndirect()) { while (k < kidsPR.size()) kidsPR.remove(k); break; } if (obj instanceof PRIndirectReference) iteratePages((PRIndirectReference) obj); else if (obj instanceof PdfDictionary) iteratePages((PdfDictionary) obj); } popPageAttributes(); } }
by invoking it in the method:
void readPages() { if (refsn != null) return; refsp = null; refsn = new ArrayList<>(); pageInh = new ArrayList<>(); PdfObject obj = reader.catalog.get(PdfName.PAGES); if (obj instanceof PRIndirectReference) iteratePages((PRIndirectReference) obj); else if (obj instanceof PdfDictionary) iteratePages((PdfDictionary) obj); pageInh = null; reader.rootPages.put(PdfName.COUNT, new PdfNumber(refsn.size())); }
I hope it is helpful. Could the final fix be included in one of the next releases?
Thanks in advance PdfReader.java.txt
The text was updated successfully, but these errors were encountered:
Fix issue LibrePDF#668
5a11cdc
da021d7
Pull requests welcome!
Sorry, something went wrong.
c338a1f
568d22e
Fix issue #668
800bd8f
Successfully merging a pull request may close this issue.
Hello,
reading a pdf file the library rises the following exception:
I temporary solved the issue by adding to the PdfReader class the method:
by invoking it in the method:
I hope it is helpful. Could the final fix be included in one of the next releases?
Thanks in advance
PdfReader.java.txt
The text was updated successfully, but these errors were encountered: