Esempio n. 1
0
        /// <summary>Sets the /P and /A values corresponding to provided annotation, which is already added to a page.
        ///     </summary>
        /// <param name="pdfAnnotation">the annotation to be set</param>
        /// <param name="pdfDocument">the corresponding document</param>
        /// <returns>this object wrapper</returns>
        public virtual iText.Kernel.Pdf.Action.PdfTarget SetAnnotation(PdfFileAttachmentAnnotation pdfAnnotation,
                                                                       PdfDocument pdfDocument)
        {
            PdfPage page = pdfAnnotation.GetPage();

            if (null == page)
            {
                throw new PdfException(PdfException.AnnotationShallHaveReferenceToPage);
            }
            else
            {
                Put(PdfName.P, new PdfNumber(pdfDocument.GetPageNumber(page) - 1));
                int indexOfAnnotation        = -1;
                IList <PdfAnnotation> annots = page.GetAnnotations();
                for (int i = 0; i < annots.Count; i++)
                {
                    if (annots[i] != null && pdfAnnotation.GetPdfObject().Equals(annots[i].GetPdfObject()))
                    {
                        indexOfAnnotation = i;
                        break;
                    }
                }
                Put(PdfName.A, new PdfNumber(indexOfAnnotation));
            }
            return(this);
        }
 public virtual void GetAnnotationSetAsIntsTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         int       pageNumber      = 1;
         int       annotationIndex = 0;
         PdfTarget target          = PdfTarget.CreateChildTarget(pageNumber, annotationIndex);
         PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation);
         NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), target.GetAnnotation(document).GetPdfObject());
     }
 }
 public virtual void GetAnnotationSetAsAnnotationTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation);
         PdfDictionary content = new PdfDictionary();
         content.Put(new PdfName("Key"), new PdfString("Value"));
         PdfTarget target = PdfTarget.Create(new PdfDictionary());
         target.SetAnnotation(annotation, document);
         NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), target.GetAnnotation(document).GetPdfObject());
     }
 }
 public virtual void GetAnnotationSetAsStringTest()
 {
     using (PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()))) {
         String    namedDestination     = "namedDestination";
         String    annotationIdentifier = "annotationIdentifier";
         PdfTarget target = PdfTarget.CreateChildTarget(namedDestination, annotationIdentifier);
         PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation(new Rectangle(0, 0, 20, 20));
         annotation.SetName(new PdfString(annotationIdentifier));
         document.AddNewPage();
         document.GetPage(1).AddAnnotation(annotation);
         document.GetCatalog().GetNameTree(PdfName.Dests).AddEntry(namedDestination, new PdfArray(new PdfNumber(1))
                                                                   );
         PdfAnnotation retrievedAnnotation = target.GetAnnotation(document);
         NUnit.Framework.Assert.AreEqual(annotation.GetPdfObject(), retrievedAnnotation.GetPdfObject());
     }
 }