private void addOutlineToPage(PdfOutline outline, Map<String, PdfObject> names) { PdfObject pageObj = outline.getDestination().getDestinationPage(names); if (pageObj instanceof PdfNumber) pageObj = getDocument().getPage(((PdfNumber) pageObj).intValue() + 1).getPdfObject(); if (pageObj != null) { List<PdfOutline> outs = pagesWithOutlines.get(pageObj); if (outs == null) { outs = new ArrayList<>(); pagesWithOutlines.put(pageObj, outs); } outs.add(outline); } }
PdfDictionary ocPropertiesDict = getPdfObject().getAsDictionary(PdfName.OCProperties); if (ocPropertiesDict != null) { if (getDocument().getWriter() != null) { ocPropertiesDict.makeIndirect(getDocument()); ocProperties = new PdfOCProperties(getDocument());
/** * 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. }
/** * This method removes all outlines associated with a given page * * @param page */ void removeOutlines(PdfPage page) { if (getDocument().getWriter() == null) { return; } if (hasOutlines()) { getOutlines(false); if (pagesWithOutlines.size() > 0) { if (pagesWithOutlines.get(page.getPdfObject()) != null) { for (PdfOutline outline : pagesWithOutlines.get(page.getPdfObject())) { outline.removeOutline(); } } } } }
/** * This method returns a complete outline tree of the whole document. * * @param updateOutlines if the flag is true, the method read the whole document and creates outline tree. * If false the method gets cached outline tree (if it was cached via calling getOutlines method before). * @return fully initialized {@link PdfOutline} object. */ PdfOutline getOutlines(boolean updateOutlines) { if (outlines != null && !updateOutlines) return outlines; if (outlines != null) { outlines.clear(); pagesWithOutlines.clear(); } outlineMode = true; PdfNameTree destsTree = getNameTree(PdfName.Dests); PdfDictionary outlineRoot = getPdfObject().getAsDictionary(PdfName.Outlines); if (outlineRoot == null) { if (null == getDocument().getWriter()) { return null; } outlines = new PdfOutline(getDocument()); } else { constructOutlines(outlineRoot, destsTree.getNames()); } return outlines; }
/** * Constructs {@link PdfCatalog#outlines} iteratively */ private void constructOutlines(PdfDictionary outlineRoot, Map<String, PdfObject> names) { if (outlineRoot == null) { return; } PdfDictionary first = outlineRoot.getAsDictionary(PdfName.First); PdfDictionary current = first; PdfDictionary next; PdfDictionary parent; HashMap<PdfDictionary, PdfOutline> parentOutlineMap = new HashMap<>(); outlines = new PdfOutline(OutlineRoot, outlineRoot, getDocument()); PdfOutline parentOutline = outlines; parentOutlineMap.put(outlineRoot, parentOutline); while (current != null) { first = current.getAsDictionary(PdfName.First); next = current.getAsDictionary(PdfName.Next); parent = current.getAsDictionary(PdfName.Parent); parentOutline = parentOutlineMap.get(parent); PdfOutline currentOutline = new PdfOutline(current.getAsString(PdfName.Title).toUnicodeString(), current, parentOutline); addOutlineToPage(currentOutline, current, names); parentOutline.getAllChildren().add(currentOutline); if (first != null) { parentOutlineMap.put(current, currentOutline); } current = getNextOutline(first, next, parent); } }
/** * This method checks a number of document-wide requirements of the PDF/A * standard. The algorithms of some of these checks vary with the PDF/A * level and thus are implemented in subclasses; others are implemented * as private methods in this class. * * @param catalog The catalog being checked */ public void checkDocument(PdfCatalog catalog) { PdfDictionary catalogDict = catalog.getPdfObject(); setPdfAOutputIntentColorSpace(catalogDict); checkOutputIntents(catalogDict); checkMetaData(catalogDict); checkCatalogValidEntries(catalogDict); checkTrailer(catalog.getDocument().getTrailer()); checkLogicalStructure(catalogDict); checkForm(catalogDict.getAsDictionary(PdfName.AcroForm)); checkOutlines(catalogDict); checkPages(catalog.getDocument()); checkOpenAction(catalogDict.get(PdfName.OpenAction)); checkColorsUsages(); }
/** * This method checks a number of document-wide requirements of the PDF/A * standard. The algorithms of some of these checks vary with the PDF/A * level and thus are implemented in subclasses; others are implemented * as private methods in this class. * * @param catalog The catalog being checked */ public void checkDocument(PdfCatalog catalog) { PdfDictionary catalogDict = catalog.getPdfObject(); setPdfAOutputIntentColorSpace(catalogDict); checkOutputIntents(catalogDict); checkMetaData(catalogDict); checkCatalogValidEntries(catalogDict); checkTrailer(catalog.getDocument().getTrailer()); checkLogicalStructure(catalogDict); checkForm(catalogDict.getAsDictionary(PdfName.AcroForm)); checkOutlines(catalogDict); checkPages(catalog.getDocument()); checkOpenAction(catalogDict.get(PdfName.OpenAction)); checkColorsUsages(); }
dic.makeIndirect(catalog.getDocument()); kids[k] = dic; int offset = i * NODE_SIZE; int end = Math.min(offset + NODE_SIZE, top); PdfDictionary dic = (PdfDictionary) new PdfDictionary().makeIndirect(catalog.getDocument()); PdfArray arr = new PdfArray(); arr.add(new PdfString(names[i * skip], null));
dic.makeIndirect(catalog.getDocument()); kids[i] = dic; int offset = k * NODE_SIZE; int end = Math.min(offset + NODE_SIZE, top); PdfDictionary dic = (PdfDictionary) new PdfDictionary().makeIndirect(catalog.getDocument()); PdfArray arr = new PdfArray(); arr.add(new PdfNumber((int) numbers[k * skip]));
PdfObject pageObject = srcDestArray.get(0); if (pageObject instanceof PdfNumber) pageObject = getDocument().getPage(((PdfNumber) pageObject).intValue() + 1).getPdfObject(); for (PdfPage oldPage : page2page.keySet()) { if (oldPage.getPdfObject() == pageObject) {