/** * Checks if it's forbidden to release this {@link PdfObject} instance. * Some objects are vital for the living period of {@link PdfDocument} or may be * prevented from releasing by high-level entities dealing with the objects. * Also it's not possible to release the objects that have been modified. */ public boolean isReleaseForbidden() { return checkState(FORBID_RELEASE); }
/** * Checks if object is indirect. * <br> * Note: * Return value {@code true} doesn't necessarily mean that indirect reference of this object * is not null at the moment. Object could be marked as indirect and * be transformed to indirect on flushing. * <br> * E.g. all PdfStreams are transformed to indirect objects when they are written, but they don't always * have indirect references at any given moment. * * @return returns {@code true} if object is indirect or is to be indirect in the resultant document. */ public boolean isIndirect() { return indirectReference != null || checkState(PdfObject.MUST_BE_INDIRECT); }
/** * Creates clone of the object which belongs to the same document as original object. * New object shall not be used in other documents. * * @return cloned object. */ @SuppressWarnings("CloneDoesntCallSuperClone") @Override public PdfObject clone() { PdfObject newObject = newInstance(); if (indirectReference != null || checkState(MUST_BE_INDIRECT)) { newObject.setState(MUST_BE_INDIRECT); } newObject.copyContent(this, null); return newObject; }
/** * Copies object to a specified document. * <br><br> * NOTE: Works only for objects that are read from document opened in reading mode, otherwise an exception is thrown. * * @param document document to copy object to. * @param allowDuplicating indicates if to allow copy objects which already have been copied. * If object is associated with any indirect reference and allowDuplicating is false then already existing reference will be returned instead of copying object. * If allowDuplicating is true then object will be copied and new indirect reference will be assigned. * @return copied object. */ public PdfObject copyTo(PdfDocument document, boolean allowDuplicating) { if (document == null) throw new PdfException(PdfException.DocumentForCopyToCannotBeNull); if (indirectReference != null) { // TODO checkState(MUST_BE_INDIRECT) now is always false, because indirectReference != null. See also DEVSIX-602 if (indirectReference.getWriter() != null || checkState(MUST_BE_INDIRECT)) { throw new PdfException(PdfException.CannotCopyIndirectObjectFromTheDocumentThatIsBeingWritten); } if (!indirectReference.getReader().isOpenedWithFullPermission()) { throw new BadPasswordException(BadPasswordException.PdfReaderNotOpenedWithOwnerPassword); } } return processCopying(document, allowDuplicating); }
if (pdfObject.checkState(PdfObject.MUST_BE_INDIRECT) && document != null) { pdfObject.makeIndirect(document); pdfObject = pdfObject.getIndirectReference(); if (pdfObject.checkState(PdfObject.READ_ONLY)) { throw new PdfException(PdfException.CannotWriteObjectAfterItWasReleased);
private void markObjectToFlush(PdfObject pdfObject) { if (pdfObject != null) { PdfIndirectReference indirectReference = pdfObject.getIndirectReference(); if (indirectReference != null) { if (!indirectReference.checkState(PdfObject.FLUSHED)) { indirectReference.setState(PdfObject.MUST_BE_FLUSHED); } } else { if (pdfObject.getType() == PdfObject.INDIRECT_REFERENCE) { if (!pdfObject.checkState(PdfObject.FLUSHED)) { pdfObject.setState(PdfObject.MUST_BE_FLUSHED); } } else if (pdfObject.getType() == PdfObject.ARRAY) { markArrayContentToFlush((PdfArray) pdfObject); } else if (pdfObject.getType() == PdfObject.DICTIONARY) { markDictionaryContentToFlush((PdfDictionary) pdfObject); } } } }
|| value.getType() == PdfObject.NULL || value.getType() == PdfObject.INDIRECT_REFERENCE || value.checkState(PdfObject.MUST_BE_INDIRECT))) { isAlreadyWriteSpace = true; writeSpace();