Ejemplo n.º 1
0
 /// <summary>Copies object to a specified document.</summary>
 /// <remarks>
 /// 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.
 /// </remarks>
 /// <param name="document">document to copy object to.</param>
 /// <param name="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.
 /// </param>
 /// <returns>copied object.</returns>
 public virtual PdfObject CopyTo(PdfDocument document, bool allowDuplicating)
 {
     if (document == null)
     {
         throw new PdfException(PdfException.DocumentToCopyToCannotBeNull);
     }
     if (indirectReference != null)
     {
         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));
 }