/** * Create a PdfDocumentInfo based on the passed PdfDictionary. * * @param pdfObject PdfDictionary containing PdfDocumentInfo */ PdfDocumentInfo(PdfDictionary pdfObject, PdfDocument pdfDocument) { infoDictionary = pdfObject; if (pdfDocument.getWriter() != null) { infoDictionary.makeIndirect(pdfDocument); } }
/** * Flush all copied objects and remove them from copied cache. * Note, if you will copy objects from the same document, doublicated objects will be created. * * @param sourceDoc source document */ public void flushCopiedObjects(PdfDocument sourceDoc) { if (getWriter() != null) { getWriter().flushCopiedObjects(sourceDoc.getDocumentId()); } }
/** * Creates a SignatureUtil instance. Sets the acroForm field to the acroForm in the PdfDocument. * iText will create a new AcroForm if the PdfDocument doesn't contain one. * * @param document PdfDocument to be inspected */ public SignatureUtil(PdfDocument document) { this.document = document; // Only create new AcroForm if there is a writer this.acroForm = PdfAcroForm.getAcroForm(document, document.getWriter() != null); }
/** * Creates a new instance of PdfSplitter class. * * @param pdfDocument the document to be split. */ public PdfSplitter(PdfDocument pdfDocument) { if (pdfDocument.getWriter() != null) { throw new PdfException(PdfException.CannotSplitDocumentThatIsBeingWritten); } this.pdfDocument = pdfDocument; this.preserveTagged = true; this.preserveOutlines = true; }
/** * Creates a SignatureUtil instance. Sets the acroForm field to the acroForm in the PdfDocument. * iText will create a new AcroForm if the PdfDocument doesn't contain one. * * @param document PdfDocument to be inspected */ public SignatureUtil(PdfDocument document) { this.document = document; // Only create new AcroForm if there is a writer this.acroForm = PdfAcroForm.getAcroForm(document, document.getWriter() != null); }
/** * Gets a PdfWriter associated with the document object belongs to. * * @return PdfWriter. */ protected PdfWriter getWriter() { if (getDocument() != null) return getDocument().getWriter(); return null; }
/** * 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(); } } } } }
/** * Marks object to be saved as indirect. * * @param document a document the indirect reference will belong to. * @return object itself. */ public PdfObject makeIndirect(PdfDocument document, PdfIndirectReference reference) { if (document == null || indirectReference != null) { return this; } if (document.getWriter() == null) { throw new PdfException(PdfException.ThereIsNoAssociatePdfWriterForMakingIndirects); } if (reference == null) { indirectReference = document.createNextIndirectReference(); indirectReference.setRefersTo(this); } else { indirectReference = reference; indirectReference.setRefersTo(this); } clearState(MUST_BE_INDIRECT); return this; }
if (getWriter() == null) { throw new PdfException(PdfException.CannotSetEncryptedPayloadToDocumentOpenedInReadingMode);
/** * Convenience method for fast PdfCanvas creation by a certain page. * * @param page page to create canvas from. */ public PdfCanvas(PdfPage page) { this(page, (page.getDocument().getReader() != null && page.getDocument().getWriter() != null && page.getContentStreamCount() > 0 && page.getLastContentStream().getLength() > 0) || (page.getRotation() != 0 && page.isIgnorePageRotationForContent())); }
/** * 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; }
if (documentTo != null) { PdfWriter writer = documentTo.getWriter(); if (writer == null) throw new PdfException(PdfException.CannotCopyToDocumentOpenedInReadingMode);
/** * Convenience method to write the fingerprint preceding the trailer. * The fingerprint contains information on iText products used in the generation or manipulation * of an outputted PDF file. * * @param document pdfDocument to write the fingerprint to */ protected static void writeKeyInfo(PdfDocument document) { PdfWriter writer = document.getWriter(); FingerPrint fingerPrint = document.getFingerPrint(); String platform = ""; VersionInfo versionInfo = document.getVersionInfo(); String k = versionInfo.getKey(); if (k == null) { k = "iText"; } writer.writeString(MessageFormatUtil.format("%{0}-{1}{2}\n", k, versionInfo.getRelease(), platform)); for (ProductInfo productInfo : fingerPrint.getProducts() ) { writer.writeString(MessageFormatUtil.format("%{0}\n", productInfo)); } }
copier.copy(this, page); } else { if (!toDocument.getWriter().isUserWarnedAboutAcroFormCopying && getDocument().getCatalog().getPdfObject().containsKey(PdfName.AcroForm)) { Logger logger = LoggerFactory.getLogger(PdfPage.class); logger.warn(LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY); toDocument.getWriter().isUserWarnedAboutAcroFormCopying = true;
PdfDictionary ocPropertiesDict = getPdfObject().getAsDictionary(PdfName.OCProperties); if (ocPropertiesDict != null) { if (getDocument().getWriter() != null) { ocPropertiesDict.makeIndirect(getDocument());
tStream.setCompressionLevel(document.getWriter().getCompressionLevel()); ar.set(t, tStream); PdfStream dStream = new PdfStream(serializeDocument(form.datasetsNode)); dStream.setCompressionLevel(document.getWriter().getCompressionLevel()); ar.set(d, dStream); ar.setModified(); stream.setCompressionLevel(document.getWriter().getCompressionLevel()); stream.flush(); acroForm.put(PdfName.XFA, stream);
protected void flushSingleRenderer(IRenderer resultRenderer) { Transform transformProp = resultRenderer.<Transform>getProperty(Property.TRANSFORM); if (!waitingDrawingElements.contains(resultRenderer)) { processWaitingDrawing(resultRenderer, transformProp, waitingDrawingElements); if (FloatingHelper.isRendererFloating(resultRenderer) || transformProp != null) return; } if (!resultRenderer.isFlushed() && null != resultRenderer.getOccupiedArea()) { // TODO Remove checking occupied area to be not null when DEVSIX-1001 is resolved. int pageNum = resultRenderer.getOccupiedArea().getPageNumber(); PdfDocument pdfDocument = document.getPdfDocument(); ensureDocumentHasNPages(pageNum, null); PdfPage correspondingPage = pdfDocument.getPage(pageNum); if (correspondingPage.isFlushed()) { throw new PdfException(PdfException.CannotDrawElementsOnAlreadyFlushedPages); } boolean wrapOldContent = pdfDocument.getReader() != null && pdfDocument.getWriter() != null && correspondingPage.getContentStreamCount() > 0 && correspondingPage.getLastContentStream().getLength() > 0 && !wrappedContentPage.contains(pageNum) && pdfDocument.getNumberOfPages() >= pageNum; wrappedContentPage.add(pageNum); if (pdfDocument.isTagged()) { pdfDocument.getTagStructureContext().getAutoTaggingPointer().setPageForTagging(correspondingPage); } resultRenderer.draw(new DrawContext(pdfDocument, new PdfCanvas(correspondingPage, wrapOldContent), pdfDocument.isTagged())); } }
protected void flushSingleRenderer(IRenderer resultRenderer) { Transform transformProp = resultRenderer.<Transform>getProperty(Property.TRANSFORM); if (!waitingDrawingElements.contains(resultRenderer)) { processWaitingDrawing(resultRenderer, transformProp, waitingDrawingElements); if (FloatingHelper.isRendererFloating(resultRenderer) || transformProp != null) return; } if (!resultRenderer.isFlushed() && null != resultRenderer.getOccupiedArea()) { // TODO Remove checking occupied area to be not null when DEVSIX-1001 is resolved. int pageNum = resultRenderer.getOccupiedArea().getPageNumber(); PdfDocument pdfDocument = document.getPdfDocument(); ensureDocumentHasNPages(pageNum, null); PdfPage correspondingPage = pdfDocument.getPage(pageNum); if (correspondingPage.isFlushed()) { throw new PdfException(PdfException.CannotDrawElementsOnAlreadyFlushedPages); } boolean wrapOldContent = pdfDocument.getReader() != null && pdfDocument.getWriter() != null && correspondingPage.getContentStreamCount() > 0 && correspondingPage.getLastContentStream().getLength() > 0 && !wrappedContentPage.contains(pageNum) && pdfDocument.getNumberOfPages() >= pageNum; wrappedContentPage.add(pageNum); if (pdfDocument.isTagged()) { pdfDocument.getTagStructureContext().getAutoTaggingPointer().setPageForTagging(correspondingPage); } resultRenderer.draw(new DrawContext(pdfDocument, new PdfCanvas(correspondingPage, wrapOldContent), pdfDocument.isTagged())); } }
public PdfPages(int from, PdfDocument pdfDocument, PdfPages parent) { super(new PdfDictionary()); if (pdfDocument.getWriter() != null) { getPdfObject().makeIndirect(pdfDocument); } setForbidRelease(); this.from = from; this.count = new PdfNumber(0); this.kids = new PdfArray(); this.parent = parent; getPdfObject().put(PdfName.Type, PdfName.Pages); getPdfObject().put(PdfName.Kids, this.kids); getPdfObject().put(PdfName.Count, this.count); if (parent != null) { getPdfObject().put(PdfName.Parent, this.parent.getPdfObject()); } }
private void copyInheritedProperties(PdfPage copyPdfPage, PdfDocument pdfDocument) { if (copyPdfPage.getPdfObject().get(PdfName.Resources) == null) { PdfObject copyResource = pdfDocument.getWriter().copyObject(getResources().getPdfObject(), pdfDocument, false); copyPdfPage.getPdfObject().put(PdfName.Resources, copyResource); } if (copyPdfPage.getPdfObject().get(PdfName.MediaBox) == null) { //media box shall be in any case copyPdfPage.setMediaBox(getMediaBox()); } if (copyPdfPage.getPdfObject().get(PdfName.CropBox) == null) { //original pdfObject don't have CropBox, otherwise copyPdfPage will contain it PdfArray cropBox = (PdfArray) getInheritedValue(PdfName.CropBox, PdfObject.ARRAY); //crop box is optional, we shall not set default value. if (cropBox != null) { copyPdfPage.put(PdfName.CropBox, cropBox.copyTo(pdfDocument)); } } if (copyPdfPage.getPdfObject().get(PdfName.Rotate) == null) { //original pdfObject don't have Rotate, otherwise copyPdfPage will contain it PdfNumber rotate = (PdfNumber) getInheritedValue(PdfName.Rotate, PdfObject.NUMBER); //rotate is optional, we shall not set default value. if (rotate != null) { copyPdfPage.put(PdfName.Rotate, rotate.copyTo(pdfDocument)); } } }