Beispiel #1
0
        /// <summary>Get the page number associated to the provided widget.</summary>
        /// <param name="widget">PdfWidgetAnnotation from which to extract the page number</param>
        /// <returns>page number</returns>
        protected internal virtual int GetWidgetPageNumber(PdfWidgetAnnotation widget)
        {
            int           pageNumber = 0;
            PdfDictionary pageDict   = widget.GetPdfObject().GetAsDictionary(PdfName.P);

            if (pageDict != null)
            {
                pageNumber = document.GetPageNumber(pageDict);
            }
            else
            {
                for (int i = 1; i <= document.GetNumberOfPages(); i++)
                {
                    PdfPage page = document.GetPage(i);
                    if (!page.IsFlushed())
                    {
                        if (page.ContainsAnnotation(widget))
                        {
                            pageNumber = i;
                            break;
                        }
                    }
                }
            }
            return(pageNumber);
        }
 public virtual void AnnotationCheckTest08()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
         Stream @is       = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 650, 400, 100);
         Rectangle formRect  = new Rectangle(400, 100);
         PdfAnnotation annot = new PdfWidgetAnnotation(rect);
         annot.SetContents(new PdfString(""));
         annot.SetFlags(PdfAnnotation.PRINT);
         annot.GetPdfObject().Put(PdfName.FT, PdfName.Btn);
         annot.SetNormalAppearance(CreateAppearance(doc, formRect));
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.APPEARANCE_DICTIONARY_OF_WIDGET_SUBTYPE_AND_BTN_FIELD_TYPE_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_DICTIONARY_VALUE))
     ;
 }
Beispiel #3
0
 public virtual void AnnotationCheckTest08()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
         Stream @is       = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 650, 400, 100);
         Rectangle formRect  = new Rectangle(400, 100);
         PdfAnnotation annot = new PdfWidgetAnnotation(rect);
         annot.SetContents(new PdfString(""));
         annot.SetFlags(PdfAnnotation.PRINT);
         annot.GetPdfObject().Put(PdfName.FT, PdfName.Btn);
         annot.SetNormalAppearance(CreateAppearance(doc, formRect));
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AppearanceDictionaryOfWidgetSubtypeAndBtnFieldTypeShallContainOnlyTheNKeyWithDictionaryValue));
     ;
 }