Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
 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())))
     ;
 }
Exemplo n.º 4
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 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 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 CreatePDF(String dest)
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest));

            // في القيام بنشاط
            String line1 = "\u0641\u064A\u0020\u0627\u0644\u0642\u064A\u0627\u0645\u0020\u0628\u0646\u0634\u0627\u0637";

            // Create a rectangle for an annotation
            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();
        }
Exemplo n.º 8
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();
        }