Пример #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));
 }
Пример #2
0
 private void Write(PdfIndirectReference indirectReference)
 {
     if (document != null && !indirectReference.GetDocument().Equals(document))
     {
         throw new PdfException(PdfException.PdfIndirectObjectBelongsToOtherPdfDocument);
     }
     if (indirectReference.IsFree())
     {
         ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Pdf.PdfOutputStream));
         logger.Error(iText.IO.LogMessageConstant.FLUSHED_OBJECT_CONTAINS_FREE_REFERENCE);
         Write(PdfNull.PDF_NULL);
     }
     else
     {
         if (indirectReference.refersTo == null && (indirectReference.CheckState(PdfObject.MODIFIED) || indirectReference
                                                    .GetReader() == null || !(indirectReference.GetOffset() > 0 || indirectReference.GetIndex() >= 0)))
         {
             ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Pdf.PdfOutputStream));
             logger.Error(iText.IO.LogMessageConstant.FLUSHED_OBJECT_CONTAINS_REFERENCE_WHICH_NOT_REFER_TO_ANY_OBJECT);
             Write(PdfNull.PDF_NULL);
         }
         else
         {
             if (indirectReference.GetGenNumber() == 0)
             {
                 WriteInteger(indirectReference.GetObjNumber()).WriteBytes(endIndirectWithZeroGenNr);
             }
             else
             {
                 WriteInteger(indirectReference.GetObjNumber()).WriteSpace().WriteInteger(indirectReference.GetGenNumber())
                 .WriteBytes(endIndirect);
             }
         }
     }
 }