public virtual void AnnotationCheckTest12()
 {
     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_2A, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         doc.SetTagged();
         doc.GetCatalog().SetLang(new PdfString("en-US"));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 650, 400, 100);
         PdfAnnotation annot = new PdfStampAnnotation(rect);
         annot.SetFlags(PdfAnnotation.PRINT);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_OF_TYPE_0_SHOULD_HAVE_CONTENTS_KEY, PdfName.Stamp.GetValue())))
     ;
 }
 public virtual void AnnotationCheckTest13()
 {
     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_2A, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         doc.SetTagged();
         doc.GetCatalog().SetLang(new PdfString("en-US"));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 650, 400, 100);
         PdfAnnotation annot = new PdfStampAnnotation(rect);
         annot.SetFlags(PdfAnnotation.PRINT);
         annot.SetContents("Hello world");
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.EVERY_ANNOTATION_SHALL_HAVE_AT_LEAST_ONE_APPEARANCE_DICTIONARY))
     ;
 }
        public virtual void AnnotationCheckTest14()
        {
            String       outPdf = destinationFolder + "pdfA2a_annotationCheckTest14.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA2a_annotationCheckTest14.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            Stream       @is    = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfADocument doc    = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent("Custom", ""
                                                                                                              , "http://www.color.org", "sRGB IEC61966-2.1", @is));

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            PdfPage       page      = doc.AddNewPage();
            Rectangle     annotRect = new Rectangle(100, 650, 400, 100);
            Rectangle     formRect  = new Rectangle(400, 100);
            PdfAnnotation annot     = new PdfStampAnnotation(annotRect);

            annot.SetFlags(PdfAnnotation.PRINT);
            annot.SetContents("Hello World");
            annot.SetNormalAppearance(CreateAppearance(doc, formRect));
            page.AddAnnotation(annot);
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }
Beispiel #4
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument    pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            ImageData      img    = ImageDataFactory.Create(IMG);
            float          width  = img.GetWidth();
            float          height = img.GetHeight();
            PdfFormXObject xObj   = new PdfFormXObject(new Rectangle(width, height));

            PdfCanvas canvas = new PdfCanvas(xObj, pdfDoc);

            canvas.AddImageAt(img, 0, 0, false);

            Rectangle          location = new Rectangle(36, 770 - height, width, height);
            PdfStampAnnotation stamp    = new PdfStampAnnotation(location);

            stamp.SetStampName(new PdfName("ITEXT"));
            stamp.SetNormalAppearance(xObj.GetPdfObject());

            // Set to print the annotation when the page is printed
            stamp.SetFlags(PdfAnnotation.PRINT);
            pdfDoc.GetFirstPage().AddAnnotation(stamp);

            pdfDoc.Close();
        }