Ejemplo n.º 1
0
        private void InsertRadioButtons(PdfPage page)
        {
            var bounds = page.GetBoundsForBox(PdfDisplayBox.Crop);

            // Yes button
            var radioButtonYesBounds = new CGRect(135, bounds.Height - 249, 24, 24);
            var radioButtonYes       = new PdfAnnotation(radioButtonYesBounds, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType         = PdfAnnotationWidgetSubtype.Button.GetConstant(),
                WidgetControlType       = PdfWidgetControlType.RadioButton,
                FieldName               = "Radio Button",
                ButtonWidgetStateString = "Yes"
            };

            page.AddAnnotation(radioButtonYes);

            // Yes button
            var radioButtonNoBounds = new CGRect(210, bounds.Height - 249, 24, 24);
            var radioButtonNo       = new PdfAnnotation(radioButtonNoBounds, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType         = PdfAnnotationWidgetSubtype.Button.GetConstant(),
                WidgetControlType       = PdfWidgetControlType.RadioButton,
                FieldName               = "Radio Button",
                ButtonWidgetStateString = "No"
            };

            page.AddAnnotation(radioButtonNo);
        }
Ejemplo n.º 2
0
        private void InsertFormFields(PdfPage page)
        {
            var bounds = page.GetBoundsForBox(PdfDisplayBox.Crop);

            var textFieldNameBox = new CGRect(169, bounds.Height - 102, 371, 23);
            var textFieldName    = new PdfAnnotation(textFieldNameBox, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType = PdfAnnotationWidgetSubtype.Text.GetConstant(),
                BackgroundColor = UIColor.Blue.ColorWithAlpha(0.25f),
                Font            = UIFont.SystemFontOfSize(18)
            };

            page.AddAnnotation(textFieldName);

            var textFieldDateBounds = new CGRect(283, bounds.Height - 135, 257, 22);
            var textFieldDate       = new PdfAnnotation(textFieldDateBounds, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType = PdfAnnotationWidgetSubtype.Text.GetConstant(),
                BackgroundColor = UIColor.Blue.ColorWithAlpha(0.25f),
                Font            = UIFont.SystemFontOfSize(18),
                MaximumLength   = 5,
                Comb            = true
            };

            page.AddAnnotation(textFieldDate);
        }
Ejemplo n.º 3
0
        private void InsertCheckBoxes(PdfPage page)
        {
            var bounds = page.GetBoundsForBox(PdfDisplayBox.Crop);

            var checkboxLoremFestivalBounds = new CGRect(255, bounds.Height - 370, 24, 24);
            var checkboxLoremFestival       = new PdfAnnotation(checkboxLoremFestivalBounds, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType   = PdfAnnotationWidgetSubtype.Button.GetConstant(),
                WidgetControlType = PdfWidgetControlType.CheckBox
            };

            page.AddAnnotation(checkboxLoremFestival);

            var checkboxIpsumFestivalBounds = new CGRect(255, bounds.Height - 417, 24, 24);
            var checkboxIpsumFestival       = new PdfAnnotation(checkboxIpsumFestivalBounds, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType   = PdfAnnotationWidgetSubtype.Button.GetConstant(),
                WidgetControlType = PdfWidgetControlType.CheckBox
            };

            page.AddAnnotation(checkboxIpsumFestival);

            var checkboxDolumFestivalBounds = new CGRect(255, bounds.Height - 464, 24, 24);
            var checkboxDolumFestival       = new PdfAnnotation(checkboxDolumFestivalBounds, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType   = PdfAnnotationWidgetSubtype.Button.GetConstant(),
                WidgetControlType = PdfWidgetControlType.CheckBox
            };

            page.AddAnnotation(checkboxDolumFestival);
        }
Ejemplo n.º 4
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc     = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfPage     firstPage  = pdfDoc.GetFirstPage();
            PdfAction   linkAction = PdfAction.CreateURI("https://pages.itextpdf.com/ebook-stackoverflow-questions.html");

            Rectangle     annotLocation = new Rectangle(30, 770, 90, 30);
            PdfAnnotation link          = new PdfLinkAnnotation(annotLocation)

                                          // Set highlighting type which is enabled after a click on the annotation
                                          .SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT)
                                          .SetAction(linkAction)
                                          .SetColor(ColorConstants.RED.GetColorValue());

            firstPage.AddAnnotation(link);

            annotLocation = new Rectangle(30, 670, 30, 90);
            link          = new PdfLinkAnnotation(annotLocation)
                            .SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT)
                            .SetAction(linkAction)
                            .SetColor(ColorConstants.GREEN.GetColorValue());
            firstPage.AddAnnotation(link);

            annotLocation = new Rectangle(150, 770, 90, 30);
            PdfAnnotation stamp = new PdfStampAnnotation(annotLocation)
                                  .SetStampName(new PdfName("Confidential"))

                                  // This method sets the text that will be displayed for the annotation or the alternate description,
                                  // if this type of annotation does not display text.
                                  .SetContents("Landscape");

            firstPage.AddAnnotation(stamp);

            annotLocation = new Rectangle(150, 670, 90, 90);
            stamp         = new PdfStampAnnotation(annotLocation)
                            .SetStampName(new PdfName("Confidential"))
                            .SetContents("Portrait")
                            .Put(PdfName.Rotate, new PdfNumber(90));
            firstPage.AddAnnotation(stamp);

            annotLocation = new Rectangle(250, 670, 90, 90);
            stamp         = new PdfStampAnnotation(annotLocation)
                            .SetStampName(new PdfName("Confidential"))
                            .SetContents("Portrait")
                            .Put(PdfName.Rotate, new PdfNumber(45));
            firstPage.AddAnnotation(stamp);

            pdfDoc.Close();
        }
Ejemplo n.º 5
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc    = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            ImageData   img       = ImageDataFactory.Create(IMG);
            float       x         = 10;
            float       y         = 650;
            float       width     = img.GetWidth();
            float       height    = img.GetHeight();
            PdfPage     firstPage = pdfDoc.GetFirstPage();

            PdfCanvas canvas = new PdfCanvas(firstPage);

            canvas.AddImageAt(img, x, y, false);

            Rectangle linkLocation = new Rectangle(x, y, width, height);

            // Make the link destination page fit to the display
            PdfExplicitDestination destination = PdfExplicitDestination.CreateFit(pdfDoc.GetLastPage());
            PdfAnnotation          annotation  = new PdfLinkAnnotation(linkLocation)

                                                 // Set highlighting type which is enabled after a click on the annotation
                                                 .SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT)

                                                 // Create a link to the last page of the document.
                                                 .SetAction(PdfAction.CreateGoTo(destination))
                                                 .SetBorder(new PdfArray(new float[] { 0, 0, 0 }));

            firstPage.AddAnnotation(annotation);

            pdfDoc.Close();
        }
Ejemplo n.º 6
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc    = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            Document    doc       = new Document(pdfDoc);
            PdfPage     firstPage = pdfDoc.GetFirstPage();

            PdfCanvas canvas = new PdfCanvas(firstPage);

            canvas
            .MoveTo(36, 700)
            .LineTo(72, 760)
            .LineTo(144, 720)
            .LineTo(72, 730)
            .ClosePathStroke();

            Rectangle linkLocation = new Rectangle(36, 700, 144, 760);

            // Make the link destination page fit to the display
            PdfExplicitDestination destination    = PdfExplicitDestination.CreateFit(firstPage);
            PdfLinkAnnotation      linkAnnotation = new PdfLinkAnnotation(linkLocation)

                                                    // Set highlighting type which is enabled after a click on the annotation
                                                    .SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT)

                                                    // Create a link to the first page of the document.
                                                    .SetAction(PdfAction.CreateGoTo(destination));
            PdfArray arrayOfQuadPoints = new PdfArray(new int[] { 72, 730, 144, 720, 72, 760, 36, 700 });

            linkAnnotation.Put(PdfName.QuadPoints, arrayOfQuadPoints);

            firstPage.AddAnnotation(linkAnnotation);

            doc.Close();
        }
Ejemplo n.º 7
0
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            // רע ומר היה להם ליהודים
            String text = "\u05E8\u05E2\u0020\u05D5\u05DE\u05E8\u0020\u05D4\u05D9\u05D4\u0020\u05DC\u05D4\u05DD" +
                          "\u0020\u05DC\u05D9\u05D4\u05D5\u05D3\u05D9\u05DD";

            // Create a rectangle for an annotation
            Rectangle rectangleAnnot = new Rectangle(55, 750, 35, 35);

            // Create the annotation, set its contents and color
            PdfAnnotation annotation = new PdfCircleAnnotation(rectangleAnnot);

            annotation
            .SetContents(text)
            .SetColor(ColorConstants.MAGENTA);

            // Add an empty page to the document, then add the annotation to the page
            PdfPage page = pdfDocument.AddNewPage();

            page.AddAnnotation(annotation);

            pdfDocument.Close();
        }
Ejemplo n.º 8
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument           pdfDoc    = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfPage               firstPage = pdfDoc.GetFirstPage();
            IList <PdfAnnotation> annots    = firstPage.GetAnnotations();

            Rectangle     stickyRectangle = annots[0].GetRectangle().ToRectangle();
            PdfAnnotation replySticky     = new PdfTextAnnotation(stickyRectangle)

                                            // This method specifies whether the annotation will initially be displayed open.
                                            .SetOpen(true)
                                            .SetIconName(new PdfName("Comment"))

                                            // This method sets an annotation to which the current annotation is "in reply".
                                            // Both annotations shall be on the same page of the document.
                                            .SetInReplyTo(annots[0])

                                            // This method sets the text label that will be displayed in the title bar of the annotation's pop-up window
                                            // when open and active. This entry shall identify the user who added the annotation.
                                            .SetText(new PdfString("Reply"))

                                            // This method sets the text that will be displayed for the annotation or the alternate description,
                                            // if this type of annotation does not display text.
                                            .SetContents("Hello PDF");

            firstPage.AddAnnotation(replySticky);

            pdfDoc.Close();
        }
Ejemplo n.º 9
0
        public virtual void CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            // সুরে মিললে সুর হবে
            String line1 =
                "\u09B8\u09C1\u09B0\u09C7\u0020\u09AE\u09BF\u09B2\u09B2\u09C7\u0020\u09B8\u09C1\u09B0\u0020\u09B9"
                + "\u09AC\u09C7";

            Rectangle rectangleAnnot = new Rectangle(55, 650, 35, 35);

            // Create a stamp annotation and set some properties
            PdfAnnotation annotation = new PdfStampAnnotation(rectangleAnnot);

            annotation
            .SetContents(line1)
            .SetColor(ColorConstants.CYAN);

            // Add an empty page to the document, then add the annotation to the page
            PdfPage page = pdfDocument.AddNewPage();

            page.AddAnnotation(annotation);

            pdfDocument.Close();
        }
Ejemplo n.º 10
0
        public override void Draw(DrawContext drawContext)
        {
            base.Draw(drawContext);
            bool isRelativePosition = IsRelativePosition();

            if (isRelativePosition)
            {
                ApplyAbsolutePositioningTranslation(false);
            }
            PdfLinkAnnotation linkAnnotation = ((Link)modelElement).GetLinkAnnotation();

            linkAnnotation.SetRectangle(new PdfArray(occupiedArea.GetBBox()));
            Border border = this.GetProperty <Border>(Property.BORDER);

            if (border != null)
            {
                linkAnnotation.SetBorder(new PdfArray(new float[] { 0, 0, border.GetWidth() }));
            }
            else
            {
                linkAnnotation.SetBorder(new PdfArray(new float[] { 0, 0, 0 }));
            }
            if (isRelativePosition)
            {
                ApplyAbsolutePositioningTranslation(true);
            }
            PdfPage page = drawContext.GetDocument().GetPage(occupiedArea.GetPageNumber());

            page.AddAnnotation(linkAnnotation);
        }
Ejemplo n.º 11
0
 public virtual void CheckAppearanceStreamWithoutTransparencyGroup()
 {
     using (MemoryStream bos = new MemoryStream()) {
         using (PdfWriter writer = new PdfWriter(bos)) {
             using (PdfDocument document = new PdfDocument(writer)) {
                 PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
                 PdfAnnotation  annotation  = new PdfPopupAnnotation(new Rectangle(0f, 0f));
                 annotation.SetNormalAppearance(formXObject.GetPdfObject());
                 PdfPage pageToCheck = document.AddNewPage();
                 pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
                 pageToCheck.AddAnnotation(annotation);
                 EnsureTransparencyObjectsNotEmpty();
                 // no assertions as we want to check that no exceptions would be thrown
                 pdfA2Checker.CheckSinglePage(pageToCheck);
             }
         }
     }
 }
Ejemplo n.º 12
0
 public virtual void CheckAppearanceStreamWithTransparencyGroup()
 {
     using (MemoryStream bos = new MemoryStream()) {
         using (PdfWriter writer = new PdfWriter(bos)) {
             using (PdfDocument document = new PdfDocument(writer)) {
                 PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
                 formXObject.SetGroup(new PdfTransparencyGroup());
                 PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
                 annotation.SetNormalAppearance(formXObject.GetPdfObject());
                 PdfPage pageToCheck = document.AddNewPage();
                 pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
                 pageToCheck.AddAnnotation(annotation);
                 NUnit.Framework.Assert.That(() => {
                     pdfA2Checker.CheckSinglePage(pageToCheck);
                 }
                                             , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE))
                 ;
             }
         }
     }
 }
Ejemplo n.º 13
0
        public void InsertMultilineTextBox(PdfPage page)
        {
            var bounds = page.GetBoundsForBox(PdfDisplayBox.Crop);

            var textFieldMultilineBox = new CGRect(90, bounds.Height - 632, 276, 80);
            var textFieldMultiline    = new PdfAnnotation(textFieldMultilineBox, PdfAnnotationSubtype.Widget.GetConstant(), null)
            {
                WidgetFieldType = PdfAnnotationWidgetSubtype.Text.GetConstant(),
                BackgroundColor = UIColor.Blue.ColorWithAlpha(0.25f),
                Font            = UIFont.SystemFontOfSize(24),
                Multiline       = true
            };

            page.AddAnnotation(textFieldMultiline);
        }
 public virtual void AnnotationCheckTest01()
 {
     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_1B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 100, 100, 100);
         PdfAnnotation annot = new PdfFileAttachmentAnnotation(rect);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(MessageFormatUtil.Format(PdfAConformanceException.ANNOTATION_TYPE_0_IS_NOT_PERMITTED, PdfName.FileAttachment.GetValue())));
     ;
 }
 public virtual void AnnotationCheckTest01()
 {
     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);
         PdfAnnotation annot = new PdfFileAttachmentAnnotation(rect);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_CONTAIN_THE_F_KEY))
     ;
 }
        public virtual void AnnotationCheckTest02()
        {
            String       outPdf = destinationFolder + "pdfA2b_annotationCheckTest02.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest02.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_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);
            PdfAnnotation annot = new PdfPopupAnnotation(rect);

            page.AddAnnotation(annot);
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }
 public virtual void AnnotationCheckTest06()
 {
     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);
         PdfAnnotation annot = new PdfTextAnnotation(rect);
         annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.INVISIBLE);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_NOVIEW_AND_TOGGLENOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0))
     ;
 }
Ejemplo n.º 18
0
 public virtual void AnnotationCheckTest03()
 {
     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_1B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page              = doc.AddNewPage();
         Rectangle rect            = new Rectangle(100, 100, 100, 100);
         PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
         annot.SetFlag(0);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.TheFKeysPrintFlagBitShallBeSetTo1AndItsHiddenInvisibleAndNoviewFlagBitsShallBeSetTo0));
     ;
 }
Ejemplo n.º 19
0
 public virtual void CheckAppearanceStreamsWithCycle()
 {
     using (MemoryStream bos = new MemoryStream()) {
         using (PdfWriter writer = new PdfWriter(bos)) {
             using (PdfDocument document = new PdfDocument(writer)) {
                 PdfDictionary normalAppearance = new PdfDictionary();
                 normalAppearance.Put(PdfName.ON, normalAppearance);
                 normalAppearance.MakeIndirect(document);
                 PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
                 annotation.SetAppearance(PdfName.N, normalAppearance);
                 PdfPage pageToCheck = document.AddNewPage();
                 pageToCheck.AddAnnotation(annotation);
                 // no assertions as we want to check that no exceptions would be thrown
                 pdfAChecker.CheckResourcesOfAppearanceStreams(annotation.GetAppearanceDictionary());
             }
         }
     }
 }
 public virtual void AnnotationCheckTest02()
 {
     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_1B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page              = doc.AddNewPage();
         Rectangle rect            = new Rectangle(100, 100, 100, 100);
         PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
         annot.SetFlag(PdfAnnotation.PRINT);
         annot.SetOpacity(new PdfNumber(0.5));
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_NOT_CONTAIN_THE_CA_KEY_WITH_A_VALUE_OTHER_THAN_1))
     ;
 }
Ejemplo n.º 21
0
 public virtual void AnnotationCheckTest02()
 {
     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_1B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page              = doc.AddNewPage();
         Rectangle rect            = new Rectangle(100, 100, 100, 100);
         PdfMarkupAnnotation annot = new PdfTextAnnotation(rect);
         annot.SetFlag(PdfAnnotation.PRINT);
         annot.SetOpacity(new PdfNumber(0.5));
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AnAnnotationDictionaryShallNotContainTheCaKeyWithAValueOtherThan1));
     ;
 }
 public virtual void AnnotationCheckTest06()
 {
     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_1B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 100, 100, 100);
         PdfAnnotation annot = new PdfWidgetAnnotation(rect);
         annot.SetFlag(PdfAnnotation.PRINT);
         annot.SetNormalAppearance(new PdfDictionary());
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.APPEARANCE_DICTIONARY_SHALL_CONTAIN_ONLY_THE_N_KEY_WITH_STREAM_VALUE))
     ;
 }
 public virtual void AnnotationCheckTest04()
 {
     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);
         PdfAnnotation annot = new PdfWidgetAnnotation(rect);
         annot.SetContents(new PdfString(""));
         annot.SetFlag(PdfAnnotation.PRINT);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.EVERY_ANNOTATION_SHALL_HAVE_AT_LEAST_ONE_APPEARANCE_DICTIONARY))
     ;
 }
Ejemplo n.º 24
0
        public virtual void CreatePdf(String dest)
        {
            //Initialize PDF document
            PdfDocument pdf         = new PdfDocument(new PdfWriter(dest));
            PdfPage     page        = pdf.AddNewPage();
            PdfArray    lineEndings = new PdfArray();

            lineEndings.Add(new PdfName("Diamond"));
            lineEndings.Add(new PdfName("Diamond"));
            //Create line annotation with inside caption
            PdfAnnotation annotation = new PdfLineAnnotation(new Rectangle(0, 0), new float[] { 20, 790, page.GetPageSize
                                                                                                    ().GetWidth() - 20, 790 }).SetLineEndingStyles((lineEndings)).SetContentsAsCaption(true).SetTitle(new
                                                                                                                                                                                                      PdfString("iText")).SetContents("The example of line annotation").SetColor(ColorConstants.BLUE);

            page.AddAnnotation(annotation);
            //Close document
            pdf.Close();
        }
Ejemplo n.º 25
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_1A, 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, 100, 100, 100);
         PdfAnnotation annot = new PdfStampAnnotation(rect);
         annot.SetFlag(PdfAnnotation.PRINT);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AnnotationOfType1ShouldHaveContentsKey));
     ;
 }
 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())))
     ;
 }
Ejemplo n.º 27
0
 public virtual void AnnotationCheckTest09()
 {
     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);
         PdfAnnotation annot = new PdfWidgetAnnotation(rect);
         annot.SetContents(new PdfString(""));
         annot.SetFlags(PdfAnnotation.PRINT);
         annot.SetNormalAppearance(new PdfDictionary());
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AppearanceDictionaryShallContainOnlyTheNKeyWithStreamValue));
     ;
 }
        public virtual void AnnotationCheckTest11()
        {
            String       outPdf = destinationFolder + "pdfA2b_annotationCheckTest11.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest11.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_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 PdfTextAnnotation(rect);

            annot.SetContents(new PdfString(""));
            annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.NO_ZOOM | PdfAnnotation.NO_ROTATE);
            annot.SetNormalAppearance(CreateAppearance(doc, formRect));
            page.AddAnnotation(annot);
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }
        public virtual void AnnotationCheckTest09()
        {
            String       outPdf = destinationFolder + "pdfA1a_annotationCheckTest09.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest09.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_1A, 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, 100, 100, 100);
            PdfAnnotation annot = new PdfStampAnnotation(rect);

            annot.SetFlag(PdfAnnotation.PRINT);
            annot.SetContents("Hello world");
            page.AddAnnotation(annot);
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }
 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))
     ;
 }