/** * 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); }