/** * Indicates if the catalog has any outlines * * @return {@code true}, if there are outlines and {@code false} otherwise. */ boolean hasOutlines() { return getPdfObject().containsKey(PdfName.Outlines); }
private void ensureTreeRootAddedToNames(PdfObject treeRoot, PdfName treeType) { PdfDictionary names = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (names == null) { names = new PdfDictionary(); catalog.put(PdfName.Names, names); names.makeIndirect(this); } names.put(treeType, treeRoot); }
public PdfCatalog put(PdfName key, PdfObject value) { getPdfObject().put(key, value); setModified(); return this; }
protected PdfCatalog(PdfDictionary pdfObject) { super(pdfObject); if (pdfObject == null) { throw new PdfException(PdfException.DocumentHasNoPdfCatalogObject); } ensureObjectIsAddedToDocument(pdfObject); getPdfObject().put(PdfName.Type, PdfName.Catalog); setForbidRelease(); pageTree = new PdfPagesTree(this); }
/** * 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; }
try { if (writer != null) { if (catalog.isFlushed()) { throw new PdfException(PdfException.CannotCloseDocumentWithAlreadyFlushedPdfCatalog); PdfStream xmp = catalog.getPdfObject().getAsStream(PdfName.Metadata); if (isAppendMode() && xmp != null && !xmp.isFlushed() && xmp.getIndirectReference() != null) { catalog.getPdfObject().put(PdfName.Metadata, xmp); catalog.setModified(); if (catalog.isOCPropertiesMayHaveChanged() && catalog.getOCProperties(false).getPdfObject().isModified()) { catalog.getOCProperties(false).flush(); catalog.put(PdfName.PageLabels, catalog.pageLabels.buildTree()); PdfObject pageRoot = catalog.getPageTree().generateTree(); if (catalog.getPdfObject().isModified() || pageRoot.isModified()) { catalog.put(PdfName.Pages, pageRoot); catalog.getPdfObject().flush(false); if (catalog.isOCPropertiesMayHaveChanged()) { catalog.getPdfObject().put(PdfName.OCProperties, catalog.getOCProperties(false).getPdfObject()); catalog.getOCProperties(false).flush(); catalog.put(PdfName.PageLabels, catalog.pageLabels.buildTree()); catalog.getPdfObject().put(PdfName.Pages, catalog.getPageTree().generateTree());
PdfDictionary acroFormDictionary = document.getCatalog().getPdfObject().getAsDictionary(PdfName.AcroForm); PdfAcroForm acroForm = null; if (acroFormDictionary == null) { acroForm = new PdfAcroForm(new PdfArray()); acroForm.makeIndirect(document); document.getCatalog().put(PdfName.AcroForm, acroForm.getPdfObject()); document.getCatalog().setModified();
return ocProperties; else { PdfDictionary ocPropertiesDict = getPdfObject().getAsDictionary(PdfName.OCProperties); if (ocPropertiesDict != null) { if (getDocument().getWriter() != null) { ocPropertiesDict.makeIndirect(getDocument()); ocProperties = new PdfOCProperties(getDocument());
catalog = new PdfCatalog((PdfDictionary) trailer.get(PdfName.Root, true)); if (catalog.getPdfObject().containsKey(PdfName.Version)) { PdfVersion catalogVersion = PdfVersion.fromPdfName(catalog.getPdfObject().getAsName(PdfName.Version)); if (catalogVersion.compareTo(pdfVersion) > 0) { pdfVersion = catalogVersion; PdfStream xmpMetadataStream = catalog.getPdfObject().getAsStream(PdfName.Metadata); if (xmpMetadataStream != null) { xmpMetadata = xmpMetadataStream.getBytes(); XmpMetaInfoConverter.appendMetadataToInfo(xmpMetadata, info); PdfDictionary str = catalog.getPdfObject().getAsDictionary(PdfName.StructTreeRoot); if (str != null) { tryInitTagStructure(str); catalog = new PdfCatalog(this); info = new PdfDocumentInfo(this).addCreationDate(); info.addModDate(); trailer = new PdfDictionary(); trailer.put(PdfName.Root, catalog.getPdfObject().getIndirectReference()); trailer.put(PdfName.Info, info.getPdfObject().getIndirectReference()); catalog.put(PdfName.Version, newPdfVersion.toPdfName()); catalog.setModified(); pdfVersion = newPdfVersion;
/** * An entry specifying the natural language, and optionally locale. Use this * to specify the Language attribute on a Tagged Pdf element. * For the content usage dictionary, use PdfName.Language */ public void setLang(PdfString lang) { put(PdfName.Lang, lang); }
document.getCatalog().setModified(); document.getCatalog().put(PdfName.Perms, docmdp); document.getCatalog().setModified();
private void outputDss(PdfDictionary dss, PdfDictionary vrim, PdfArray ocsps, PdfArray crls, PdfArray certs) throws IOException { PdfCatalog catalog = document.getCatalog(); if (document.getPdfVersion().compareTo(PdfVersion.PDF_2_0) < 0) { catalog.addDeveloperExtension(PdfDeveloperExtension.ESIC_1_7_EXTENSIONLEVEL5); catalog.put(PdfName.DSS, dss);
/** * 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(); } } } } }
/** * 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); } }
PdfNameTree destsTree = getNameTree(PdfName.Dests); Map<String, PdfObject> dests = destsTree.getNames(); String srcDestName = dest.isString() ? ((PdfString) dest).toUnicodeString() : ((PdfName) dest).getValue(); 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) { d = new PdfStringDestination(srcDestName); if (!isEqualSameNameDestExist(page2page, toDocument, srcDestName, srcDestArray, oldPage)) {
acroForm.setModified(); if (!acroForm.getPdfObject().isIndirect()) { document.getCatalog().setModified(); acroForm.setModified(); if (!acroForm.getPdfObject().isIndirect()) { document.getCatalog().setModified();
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); } }
pdfDoc.getCatalog().remove(PdfName.Outlines); return;
protected void addDeveloperExtension(PdfDeveloperExtension extension) { document.getCatalog().addDeveloperExtension(extension); }
PdfDictionary acroFormDictionary = document.getCatalog().getPdfObject().getAsDictionary(PdfName.AcroForm); PdfAcroForm acroForm = null; if (acroFormDictionary == null) { acroForm = new PdfAcroForm(new PdfArray()); acroForm.makeIndirect(document); document.getCatalog().put(PdfName.AcroForm, acroForm.getPdfObject()); document.getCatalog().setModified();