Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public virtual void ImageResizedParentWithHardMaskTest()
        {
            String      outFileName = destinationFolder + "imageResizedParentWithHardMask.pdf";
            String      cmpFileName = sourceFolder + "cmp_imageResizedParentWithHardMask.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            ImageData   mask        = ImageDataFactory.Create(sourceFolder + "hardMask.png");

            mask.MakeMask();
            ImageData img1 = ImageDataFactory.Create(sourceFolder + "sRGBImageBig.png");

            img1.SetImageMask(mask);
            ImageData img2 = ImageDataFactory.Create(sourceFolder + "sRGBImage.png");

            img2.SetImageMask(mask);
            PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());

            canvas.AddImageAt(img1, 30, 500, false);
            canvas.AddImageAt(img2, 430, 500, false);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             ));
        }
Exemplo n.º 3
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();
        }