Skip to content

Commit

Permalink
Fix issue LibrePDF#668
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Raccagni committed Feb 25, 2022
1 parent 8e4109b commit c338a1f
Show file tree
Hide file tree
Showing 2 changed files with 4,024 additions and 3 deletions.
35 changes: 32 additions & 3 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3558,7 +3558,11 @@ void readPages() {
refsp = null;
refsn = new ArrayList<>();
pageInh = new ArrayList<>();
iteratePages((PRIndirectReference) reader.catalog.get(PdfName.PAGES));
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()));
}
Expand Down Expand Up @@ -3739,7 +3743,7 @@ private void iteratePages(PRIndirectReference rpage) {
}
if (page.get(PdfName.MEDIABOX) == null) {
PdfArray arr = new PdfArray(new float[] { 0, 0,
PageSize.LETTER.getRight(), PageSize.LETTER.getTop() });
PageSize.LETTER.getRight(), PageSize.LETTER.getTop() });
page.put(PdfName.MEDIABOX, arr);
}
refsn.add(rpage);
Expand All @@ -3755,7 +3759,32 @@ private void iteratePages(PRIndirectReference rpage) {
kidsPR.remove(k);
break;
}
iteratePages((PRIndirectReference) obj);
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();
}
Expand Down
Loading

0 comments on commit c338a1f

Please sign in to comment.