protected PdfPages findPageParent(PdfPage pdfPage) { int pageNum = getPageNumber(pdfPage) - 1; int parentIndex = findPageParent(pageNum); return parents.get(parentIndex); }
/** * Returns the {@see PdfPage} at the specified position in this list. * * @param pageNum one-based index of the element to return * @return the {@see PdfPage} at the specified position in this list */ public PdfPage getPage(int pageNum) { if (pageNum < 1 || pageNum > getNumberOfPages()) { throw new IndexOutOfBoundsException(MessageFormatUtil.format(PdfException.RequestedPageNumberIsOutOfBounds, pageNum)); } --pageNum; PdfPage pdfPage = pages.get(pageNum); if (pdfPage == null) { loadPage(pageNum); if (pageRefs.get(pageNum) != null) { int parentIndex = findPageParent(pageNum); pdfPage = new PdfPage(pageRefs.get(pageNum)); pdfPage.parentPages = parents.get(parentIndex); } else { LoggerFactory.getLogger(getClass()).error(MessageFormatUtil.format(LogMessageConstant.PAGE_TREE_IS_BROKEN_FAILED_TO_RETRIEVE_PAGE, pageNum + 1)); } pages.set(pageNum, pdfPage); } return pdfPage; }
private boolean internalRemovePage(int pageNum) { int parentIndex = findPageParent(pageNum); PdfPages pdfPages = parents.get(parentIndex); if (pdfPages.removePage(pageNum)) { if (pdfPages.getCount() == 0) { parents.remove(parentIndex); pdfPages.removeFromParent(); --parentIndex; } if (parents.size() == 0) { root = null; parents.add(new PdfPages(0, document)); } else { correctPdfPagesFromProperty(parentIndex + 1, -1); } pageRefs.remove(pageNum); pages.remove(pageNum); return true; } else { return false; } }
/** * Insert {@see PdfPage} into specific one-based position. * * @param index one-base index of the page * @param pdfPage {@link PdfPage} to insert. */ public void addPage(int index, PdfPage pdfPage) { --index; if (index > pageRefs.size()) throw new IndexOutOfBoundsException("index"); if (index == pageRefs.size()) { addPage(pdfPage); return; } loadPage(index); pdfPage.makeIndirect(document); int parentIndex = findPageParent(index); PdfPages parentPages = parents.get(parentIndex); parentPages.addPage(index, pdfPage); pdfPage.parentPages = parentPages; correctPdfPagesFromProperty(parentIndex + 1, +1); pageRefs.add(index, pdfPage.getPdfObject()); pages.add(index, pdfPage); }
private PdfObject getInheritedValue(PdfName pdfName, int type) { if (this.parentPages == null) { this.parentPages = getDocument().getCatalog().getPageTree().findPageParent(this); } PdfObject val = getInheritedValue(this.parentPages, pdfName); return val != null && val.getType() == type ? val : null; }
return; int parentIndex = findPageParent(pageNum); PdfPages parent = parents.get(parentIndex); PdfArray kids = parent.getKids();