public void release() { // In case ForbidRelease flag is set, release will not be performed. if (isReleaseForbidden()) { Logger logger = LoggerFactory.getLogger(PdfObject.class); logger.warn(LogMessageConstant.FORBID_RELEASE_IS_SET); } else { if (indirectReference != null && indirectReference.getReader() != null && !indirectReference.checkState(FLUSHED)) { indirectReference.refersTo = null; indirectReference = null; setState(READ_ONLY); } //TODO log reasonless call of method } }
/** * Gets direct object and try to resolve indirects chain. * <p> * Note: If chain of references has length of more than 32, * this method return 31st reference in chain. * </p> */ public PdfObject getRefersTo(boolean recursively) { if (!recursively) { if (refersTo == null && !checkState(FLUSHED) && !checkState(MODIFIED) && !checkState(FREE) && getReader() != null) { refersTo = getReader().readObject(this); } return refersTo; } else { PdfObject currentRefersTo = getRefersTo(false); for (int i = 0; i < LENGTH_OF_INDIRECTS_CHAIN; i++) { if (currentRefersTo instanceof PdfIndirectReference) currentRefersTo = ((PdfIndirectReference) currentRefersTo).getRefersTo(false); else break; } return currentRefersTo; } }
/** * 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); }
PdfReader reader = getIndirectReference().getReader(); if (reader != null) { try {
if (outputStreamIsUninitialized && getIndirectReference() != null && getIndirectReference().getReader() != null || !outputStreamIsUninitialized && containsKey(PdfName.Filter)) {