Esempio n. 1
0
        public virtual iText.Kernel.Pdf.PdfPage AddAnnotation(int index, PdfAnnotation annotation, bool tagAnnotation
                                                              )
        {
            if (GetDocument().IsTagged() && tagAnnotation)
            {
                TagTreePointer           tagPointer = GetDocument().GetTagStructureContext().GetAutoTaggingPointer();
                iText.Kernel.Pdf.PdfPage prevPage   = tagPointer.GetCurrentPage();
                // TODO what about if current tagging stream is set
                tagPointer.SetPageForTagging(this).AddAnnotationTag(annotation);
                if (prevPage != null)
                {
                    tagPointer.SetPageForTagging(prevPage);
                }
            }
            PdfArray annots = GetAnnots(true);

            if (index == -1)
            {
                annots.Add(annotation.SetPage(this).GetPdfObject());
            }
            else
            {
                annots.Add(index, annotation.SetPage(this).GetPdfObject());
            }
            if (annots.GetIndirectReference() == null)
            {
                SetModified();
            }
            return(this);
        }
Esempio n. 2
0
        /// <summary>Copies page to the specified document.</summary>
        /// <remarks>
        /// Copies page to the specified document.
        /// <br/><br/>
        /// NOTE: Works only for pages from the document opened in reading mode, otherwise an exception is thrown.
        /// </remarks>
        /// <param name="toDocument">a document to copy page to.</param>
        /// <param name="copier">a copier which bears a specific copy logic. May be NULL</param>
        /// <returns>copied page.</returns>
        public virtual iText.Kernel.Pdf.PdfPage CopyTo(PdfDocument toDocument, IPdfPageExtraCopier copier)
        {
            PdfDictionary dictionary = GetPdfObject().CopyTo(toDocument, excludedKeys, true);

            iText.Kernel.Pdf.PdfPage page = new iText.Kernel.Pdf.PdfPage(dictionary);
            CopyInheritedProperties(page, toDocument);
            foreach (PdfAnnotation annot in GetAnnotations())
            {
                if (annot.GetSubtype().Equals(PdfName.Link))
                {
                    GetDocument().StoreLinkAnnotation(this, (PdfLinkAnnotation)annot);
                }
                else
                {
                    page.AddAnnotation(-1, PdfAnnotation.MakeAnnotation(((PdfDictionary)annot.GetPdfObject().CopyTo(toDocument
                                                                                                                    , false))), false);
                }
            }
            if (toDocument.IsTagged())
            {
                page.structParents = (int)toDocument.GetNextStructParentIndex();
                page.GetPdfObject().Put(PdfName.StructParents, new PdfNumber(page.structParents));
            }
            if (copier != null)
            {
                copier.Copy(this, page);
            }
            else
            {
                if (!toDocument.GetWriter().isUserWarnedAboutAcroFormCopying&& GetDocument().GetCatalog().GetPdfObject().
                    ContainsKey(PdfName.AcroForm))
                {
                    ILogger logger = LoggerFactory.GetLogger(typeof(iText.Kernel.Pdf.PdfPage));
                    logger.Warn(LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY);
                    toDocument.GetWriter().isUserWarnedAboutAcroFormCopying = true;
                }
            }
            return(page);
        }
Esempio n. 3
0
 private void CopyInheritedProperties(iText.Kernel.Pdf.PdfPage copyPdfPage, PdfDocument pdfDocument)
 {
     if (copyPdfPage.GetPdfObject().Get(PdfName.Resources) == null)
     {
         PdfObject copyResource = pdfDocument.GetWriter().CopyObject(GetResources().GetPdfObject(), pdfDocument, false
                                                                     );
         copyPdfPage.GetPdfObject().Put(PdfName.Resources, copyResource);
     }
     if (copyPdfPage.GetPdfObject().Get(PdfName.MediaBox) == null)
     {
         copyPdfPage.SetMediaBox(GetMediaBox());
     }
     if (copyPdfPage.GetPdfObject().Get(PdfName.CropBox) == null)
     {
         InitParentPages();
         PdfArray cropBox = (PdfArray)GetParentValue(parentPages, PdfName.CropBox);
         if (cropBox != null)
         {
             copyPdfPage.SetCropBox(cropBox.ToRectangle());
         }
     }
 }