/** * 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); }
/** * Appends the specified {@see PdfPage} to the end of this tree. * * @param pdfPage {@see PdfPage} */ public void addPage(PdfPage pdfPage) { PdfPages pdfPages; if (root != null) { // in this case we save tree structure if (pageRefs.size() == 0) { pdfPages = root; } else { loadPage(pageRefs.size() - 1); pdfPages = parents.get(parents.size() - 1); } } else { pdfPages = parents.get(parents.size() - 1); if (pdfPages.getCount() % leafSize == 0 && pageRefs.size() > 0) { pdfPages = new PdfPages(pdfPages.getFrom() + pdfPages.getCount(), document); parents.add(pdfPages); } } pdfPage.makeIndirect(document); pdfPages.addPage(pdfPage.getPdfObject()); pdfPage.parentPages = pdfPages; pageRefs.add(pdfPage.getPdfObject()); pages.add(pdfPage); }
lastPdfPages.addPage(pdfPagesObject); kidsCount--; } else { // pdfPagesObject is PdfPages