示例#1
0
        public virtual void RemoteGoToDestinationTest01()
        {
            String      cmpFile = sourceFolder + "cmp_remoteGoToDestinationTest01.pdf";
            String      outFile = destinationFolder + "remoteGoToDestinationTest01.pdf";
            PdfDocument @out    = new PdfDocument(new PdfWriter(outFile));

            @out.AddNewPage();
            IList <PdfDestination> destinations = new List <PdfDestination>(7);

            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFit(1));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitH(1, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitV(1, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitR(1, 10, 10, 10, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitB(1));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitBH(1, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitBV(1, 10));
            int y = 785;

            foreach (PdfDestination destination in destinations)
            {
                PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, y, 160, 15));
                PdfAction         action           = PdfAction.CreateGoToR(new PdfStringFS("Some fake destination"), destination);
                linkExplicitDest.SetAction(action);
                @out.GetFirstPage().AddAnnotation(linkExplicitDest);
                y -= 20;
            }
            @out.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
示例#2
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                PdfLinkAnnotation linkAnnotation = new PdfLinkAnnotation(GetOccupiedAreaBBox());

                linkAnnotation.SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
                linkAnnotation.SetAction(PdfAction.CreateURI(url));
                drawContext.GetDocument().GetLastPage().AddAnnotation(linkAnnotation);
            }
示例#3
0
        public virtual void RemoteGoToNotValidExplicitDestinationTest()
        {
            String      cmpFile  = sourceFolder + "cmp_remoteGoToNotValidExplicitDestinationTest.pdf";
            String      outFile  = destinationFolder + "remoteGoToNotValidExplicitDestinationTest.pdf";
            PdfDocument document = new PdfDocument(new PdfWriter(outFile));

            document.AddNewPage();
            PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15));

            linkExplicitDest.SetAction(PdfAction.CreateGoTo(PdfExplicitRemoteGoToDestination.CreateFit(1)));
            document.GetFirstPage().AddAnnotation(linkExplicitDest);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
示例#4
0
        public virtual void RemoteGoToRByStringDestinationTest()
        {
            String      cmpFile = sourceFolder + "cmp_remoteGoToRByStringDestinationTest.pdf";
            String      outFile = destinationFolder + "remoteGoToRByStringDestinationTest.pdf";
            PdfDocument @out    = new PdfDocument(new PdfWriter(outFile));

            @out.AddNewPage();
            PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15));
            PdfAction         action           = PdfAction.CreateGoToR("Some fake destination", "1");

            linkExplicitDest.SetAction(action);
            @out.GetFirstPage().AddAnnotation(linkExplicitDest);
            @out.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
示例#5
0
        public virtual void StructureDestination01Test()
        {
            String                  srcFile          = sourceFolder + "customRolesMappingPdf2.pdf";
            String                  outFile          = destinationFolder + "structureDestination01Test.pdf";
            String                  cmpFile          = sourceFolder + "cmp_structureDestination01Test.pdf";
            PdfDocument             document         = new PdfDocument(new PdfReader(srcFile), new PdfWriter(outFile));
            PdfStructElem           imgElement       = new PdfStructElem((PdfDictionary)document.GetPdfObject(13));
            PdfStructureDestination dest             = PdfStructureDestination.CreateFit(imgElement);
            PdfPage                 secondPage       = document.AddNewPage();
            PdfLinkAnnotation       linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15));

            linkExplicitDest.SetAction(PdfAction.CreateGoTo(dest));
            secondPage.AddAnnotation(linkExplicitDest);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
        protected internal virtual void ApplyAction(PdfDocument document)
        {
            PdfAction action = this.GetProperty <PdfAction>(Property.ACTION);

            if (action != null)
            {
                PdfLinkAnnotation link = new PdfLinkAnnotation(GetOccupiedArea().GetBBox());
                link.SetAction(action);
                Border border = this.GetProperty <Border>(Property.BORDER);
                if (border != null)
                {
                    link.SetBorder(new PdfArray(new float[] { 0, 0, border.GetWidth() }));
                }
                else
                {
                    link.SetBorder(new PdfArray(new float[] { 0, 0, 0 }));
                }
                document.GetPage(GetOccupiedArea().GetPageNumber()).AddAnnotation(link);
            }
        }
示例#7
0
        public virtual void DestTest01()
        {
            String            srcFile          = sourceFolder + "simpleNoLinks.pdf";
            String            outFile          = destinationFolder + "destTest01.pdf";
            String            cmpFile          = sourceFolder + "cmp_destTest01.pdf";
            PdfDocument       document         = new PdfDocument(new PdfReader(srcFile), new PdfWriter(outFile));
            PdfPage           firstPage        = document.GetPage(1);
            PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15));

            linkExplicitDest.SetAction(PdfAction.CreateGoTo(PdfExplicitDestination.CreateFit(document.GetPage(2))));
            firstPage.AddAnnotation(linkExplicitDest);
            PdfLinkAnnotation      linkStringDest = new PdfLinkAnnotation(new Rectangle(35, 760, 160, 15));
            PdfExplicitDestination destToPage3    = PdfExplicitDestination.CreateFit(document.GetPage(3));
            String stringDest = "thirdPageDest";

            document.AddNamedDestination(stringDest, destToPage3.GetPdfObject());
            linkStringDest.SetAction(PdfAction.CreateGoTo(new PdfStringDestination(stringDest)));
            firstPage.AddAnnotation(linkStringDest);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
示例#8
0
        private static void CreateLink(object document, Link.LinkControl control, Paragraph header, bool border)
        {
            for (int k = 0; k < control.Controls.Count; k++)
            {
                if (control.Controls[k].GetType() == typeof(LinkLabel))
                {
                    Style     style = new Style();
                    LinkLabel label = control.Controls[k] as LinkLabel;
                    iText.Kernel.Geom.Rectangle rect       = new iText.Kernel.Geom.Rectangle(0, 0);
                    PdfLinkAnnotation           annotation = new PdfLinkAnnotation(rect);
                    PdfAction action = PdfAction.CreateURI(label.Links[0].LinkData.ToString());
                    annotation.SetAction(action);
                    annotation.SetContents(label.ContextMenuStrip.Text);
                    iText.Layout.Element.Link link = new iText.Layout.Element.Link(label.Text, annotation);
                    style.SetFont(PdfFontFactory.CreateFont("C:\\Windows\\Fonts\\times.ttf", "Cp1251", true));
                    style.SetFontSize(label.Font.Size);
                    if (label.Font.Bold)
                    {
                        style.SetBold();
                    }
                    if (label.Font.Italic)
                    {
                        style.SetItalic();
                    }
                    style.SetUnderline();
                    if (label.Font.Strikeout)
                    {
                        style.SetLineThrough();
                    }
                    style.SetFontColor(ColorConstants.BLUE);
                    header.Add(link.AddStyle(style));
                    #region Анотация, которую я так и не смог сделать

                    /*
                     * // Creating a PdfTextMarkupAnnotation object
                     * rect = new Rectangle(35, 785, 0, 0);
                     * float[] floatArray = new float[] { 35, 785, 45, 785, 35, 795, 45, 795 };
                     * PdfAnnotation Annotation = PdfTextMarkupAnnotation.CreateUnderline(rect, floatArray);
                     *
                     * // Setting color to the annotation
                     * Annotation.SetColor(ColorConstants.BLUE);
                     *
                     * // Setting title to the annotation
                     * Annotation.SetTitle(new PdfString(label.ContextMenuStrip.Text));
                     *
                     * // Setting contents to the annotation
                     * Annotation.SetContents(" ");
                     *
                     * // Creating a new Pdfpage
                     * PdfPage pdfPage = pdf.AddNewPage();
                     *
                     * // Adding annotation to a page in a PDF
                     * pdfPage.AddAnnotation(Annotation);
                     */
                    #endregion
                }
                else
                {
                    ImageText.ImageTextControl picture = (control.Controls[k] as ImageText.ImageTextControl);
                    CreateImage(document, picture, true, ref header, border, k + 1 == control.Controls.Count);
                }
            }
        }