private void markUsed(PdfObject obj) { if (!append) return; ((PdfStamperImp)writer).markUsed(obj); }
private void markUsed(PdfObject obj) { if (!append) return; ((PdfStamperImp)writer).markUsed(obj); }
/** * Marks the specified object as used or changed. Used objects will be written to a new revision when using PdfStamper * in append mode. The specified PdfObject needs to be an Indirect Reference or its getIndRef() method should not * return null. * * @param obj the used PDF object */ public void markUsed(PdfObject obj) { stamper.markUsed(obj); }
/** * Marks the specified object as used or changed. Used objects will be written to a new revision when using PdfStamper * in append mode. The specified PdfObject needs to be an Indirect Reference or its getIndRef() method should not * return null. * * @param obj the used PDF object */ public void markUsed(PdfObject obj) { stamper.markUsed(obj); }
protected void setOutlines() throws IOException { if (newBookmarks == null) return; deleteOutlines(); if (newBookmarks.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); boolean namedAsNames = catalog.get(PdfName.DESTS) != null; writeOutlines(catalog, namedAsNames); markUsed(catalog); }
protected void setViewerPreferences() { reader.setViewerPreferences(viewerPreferences); markUsed(reader.getTrailer().get(PdfName.ROOT)); }
protected void setOutlines() throws IOException { if (newBookmarks == null) return; deleteOutlines(); if (newBookmarks.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); boolean namedAsNames = catalog.get(PdfName.DESTS) != null; writeOutlines(catalog, namedAsNames); markUsed(catalog); }
protected void setViewerPreferences() { reader.setViewerPreferences(viewerPreferences); markUsed(reader.getTrailer().get(PdfName.ROOT)); }
/** * Sets the display duration for the page (for presentations) * * @param seconds the number of seconds to display the page. A negative value removes the entry * @param page the page where the duration will be applied. The first page is 1 */ void setDuration(int seconds, int page) { PdfDictionary pg = reader.getPageN(page); if (seconds < 0) pg.remove(PdfName.DUR); else pg.put(PdfName.DUR, new PdfNumber(seconds)); markUsed(pg); }
/** * Sets the transition for the page * * @param transition the transition object. A <code>null</code> removes the transition * @param page the page where the transition will be applied. The first page is 1 */ void setTransition(PdfTransition transition, int page) { PdfDictionary pg = reader.getPageN(page); if (transition == null) pg.remove(PdfName.TRANS); else pg.put(PdfName.TRANS, transition.getTransitionDictionary()); markUsed(pg); }
void addDocumentField(PdfIndirectReference ref) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acroForm = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM), catalog); if (acroForm == null) { acroForm = new PdfDictionary(); catalog.put(PdfName.ACROFORM, acroForm); markUsed(catalog); } PdfArray fields = (PdfArray) PdfReader.getPdfObject(acroForm.get(PdfName.FIELDS), acroForm); if (fields == null) { fields = new PdfArray(); acroForm.put(PdfName.FIELDS, fields); markUsed(acroForm); } if (!acroForm.contains(PdfName.DA)) { acroForm.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g ")); markUsed(acroForm); } fields.add(ref); markUsed(fields); }
/** * Sets the transition for the page * * @param transition the transition object. A <code>null</code> removes the transition * @param page the page where the transition will be applied. The first page is 1 */ void setTransition(PdfTransition transition, int page) { PdfDictionary pg = reader.getPageN(page); if (transition == null) pg.remove(PdfName.TRANS); else pg.put(PdfName.TRANS, transition.getTransitionDictionary()); markUsed(pg); }
/** * Sets the display duration for the page (for presentations) * * @param seconds the number of seconds to display the page. A negative value removes the entry * @param page the page where the duration will be applied. The first page is 1 */ void setDuration(int seconds, int page) { PdfDictionary pg = reader.getPageN(page); if (seconds < 0) pg.remove(PdfName.DUR); else pg.put(PdfName.DUR, new PdfNumber(seconds)); markUsed(pg); }
protected void setJavaScript() throws IOException { HashMap<String, PdfObject> djs = pdf.getDocumentLevelJS(); if (djs.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); PdfDictionary names = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.NAMES), catalog); if (names == null) { names = new PdfDictionary(); catalog.put(PdfName.NAMES, names); markUsed(catalog); } markUsed(names); PdfDictionary tree = PdfNameTree.writeTree(djs, this); names.put(PdfName.JAVASCRIPT, addToBody(tree).getIndirectReference()); }
protected void setJavaScript() throws IOException { HashMap<String, PdfObject> djs = pdf.getDocumentLevelJS(); if (djs.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); PdfDictionary names = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.NAMES), catalog); if (names == null) { names = new PdfDictionary(); catalog.put(PdfName.NAMES, names); markUsed(catalog); } markUsed(names); PdfDictionary tree = PdfNameTree.writeTree(djs, this); names.put(PdfName.JAVASCRIPT, addToBody(tree).getIndirectReference()); }
void deleteOutlines() { PdfDictionary catalog = reader.getCatalog(); PdfObject obj = catalog.get(PdfName.OUTLINES); if (obj == null) return; if (obj instanceof PRIndirectReference) { PRIndirectReference outlines = (PRIndirectReference) obj; outlineTravel(outlines); PdfReader.killIndirect(outlines); } catalog.remove(PdfName.OUTLINES); markUsed(catalog); }
void deleteOutlines() { PdfDictionary catalog = reader.getCatalog(); PdfObject obj = catalog.get(PdfName.OUTLINES); if (obj == null) return; if (obj instanceof PRIndirectReference) { PRIndirectReference outlines = (PRIndirectReference) obj; outlineTravel(outlines); PdfReader.killIndirect(outlines); } catalog.remove(PdfName.OUTLINES); markUsed(catalog); }
static void mergeResources(PdfDictionary result, PdfDictionary source, PdfStamperImp writer) { PdfDictionary dic = null; PdfDictionary res = null; PdfName target = null; for (int k = 0; k < mergeTarget.length; ++k) { target = mergeTarget[k]; PdfDictionary pdfDict = source.getAsDict(target); if ((dic = pdfDict) != null) { if ((res = (PdfDictionary)PdfReader.getPdfObject(result.get(target), result)) == null) { res = new PdfDictionary(); } res.mergeDifferent(dic); result.put(target, res); if (writer != null) writer.markUsed(res); } } }
static void mergeResources(PdfDictionary result, PdfDictionary source, PdfStamperImp writer) { PdfDictionary dic = null; PdfDictionary res = null; PdfName target = null; for (int k = 0; k < mergeTarget.length; ++k) { target = mergeTarget[k]; PdfDictionary pdfDict = source.getAsDict(target); if ((dic = pdfDict) != null) { if ((res = (PdfDictionary)PdfReader.getPdfObject(result.get(target), result)) == null) { res = new PdfDictionary(); } res.mergeDifferent(dic); result.put(target, res); if (writer != null) writer.markUsed(res); } } }
/** * Sets the open and close page additional action. * * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE> * or <CODE>PdfWriter.PAGE_CLOSE</CODE> * @param action the action to perform * @param page the page where the action will be applied. The first page is 1 * @throws PdfException if the action type is invalid */ void setPageAction(PdfName actionType, PdfAction action, int page) throws PdfException { if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE)) throw new PdfException(MessageLocalization.getComposedMessage("invalid.page.additional.action.type.1", actionType.toString())); PdfDictionary pg = reader.getPageN(page); PdfDictionary aa = (PdfDictionary) PdfReader.getPdfObject(pg.get(PdfName.AA), pg); if (aa == null) { aa = new PdfDictionary(); pg.put(PdfName.AA, aa); markUsed(pg); } aa.put(actionType, action); markUsed(aa); }