public int compareTo(int index) { if (index < from) return 1; if (index >= from + getCount()) return -1; return 0; }
public boolean removePage(int pageNum) { if (pageNum < from || pageNum >= from + getCount()) return false; decrementCount(); kids.remove(pageNum - from); return true; }
/** * 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); }
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; } }
for (int i = 0; i < parents.size(); i++) { PdfPages pages = parents.get(i); int pageCount = pages.getCount(); if (i % dynamicLeafSize == 0) { if (pageCount <= 1) {
/** * Create PdfPages tree. * * @param pdfCatalog {@see PdfCatalog} */ public PdfPagesTree(PdfCatalog pdfCatalog) { this.document = pdfCatalog.getDocument(); this.pageRefs = new ArrayList<>(); this.parents = new ArrayList<>(); this.pages = new ArrayList<>(); if (pdfCatalog.getPdfObject().containsKey(PdfName.Pages)) { PdfDictionary pages = pdfCatalog.getPdfObject().getAsDictionary(PdfName.Pages); if (pages == null) throw new PdfException(PdfException.InvalidPageStructurePagesPagesMustBePdfDictionary); this.root = new PdfPages(0, Integer.MAX_VALUE, pages, null); parents.add(this.root); for (int i = 0; i < this.root.getCount(); i++) { this.pageRefs.add(null); this.pages.add(null); } } else { this.root = null; this.parents.add(new PdfPages(0, this.document)); } //in read mode we will create PdfPages from 0 to Count // and reserve null indexes for pageRefs and pages. }
public boolean addPage(int index, PdfPage pdfPage) { if (index < from || index > from + getCount()) return false; kids.add(index - from, pdfPage.getPdfObject()); pdfPage.getPdfObject().put(PdfName.Parent, getPdfObject()); incrementCount(); setModified(); return true; }
throw new PdfException(PdfException.InvalidPageStructure1).setMessageParams(pageNum + 1); int kidsCount = parent.getCount(); int from = lastPdfPages == null ? parent.getFrom() : lastPdfPages.getFrom() + lastPdfPages.getCount(); lastPdfPages = new PdfPages(from, kidsCount, pdfPagesObject, parent); newParents.add(lastPdfPages); kidsCount -= lastPdfPages.getCount(); for (int i = 0; i < parent.getCount(); i++) { pageRefs.set(from + i, kids.getAsDictionary(i));
public void addPages(PdfPages pdfPages) { kids.add(pdfPages.getPdfObject()); count.setValue(count.intValue() + pdfPages.getCount()); pdfPages.getPdfObject().put(PdfName.Parent, getPdfObject()); setModified(); }