Beispiel #1
0
        /// <summary>
        /// Adds a link to a file.
        /// </summary>
        /// <param name="rect">The rect.</param>
        /// <param name="fileName">Name of the file.</param>
        public PdfLinkAnnotation AddFileLink(PdfRectangle rect, string fileName)
        {
            PdfLinkAnnotation annotation = PdfLinkAnnotation.CreateFileLink(rect, fileName);

            Annotations.Add(annotation);
            return(annotation);
        }
Beispiel #2
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();
        }
Beispiel #3
0
        private static void CreateJavaScriptActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Graphics.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PdfJavaScriptAction jsAction = new PdfJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
                link.Action     = jsAction;
            }
        }
Beispiel #4
0
        private static void CreateUriActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Uri actions:", font, blackBrush, 400, 420);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 440, 200, 20);
                slo.X = 500;
                slo.Y = 450;
                document.Pages[i].Graphics.DrawString("Go to xfiniumpdf.com", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 440, 200, 20);

                // Create an uri action and attach it to the link.
                PdfUriAction uriAction = new PdfUriAction();
                uriAction.URI = "http://www.xfiniumpdf.com";
                link.Action   = uriAction;
            }
        }
Beispiel #5
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);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a link to the Web.
        /// </summary>
        /// <param name="rect">The rect.</param>
        /// <param name="url">The URL.</param>
        public PdfLinkAnnotation AddWebLink(PdfRectangle rect, string url)
        {
            PdfLinkAnnotation annotation = PdfLinkAnnotation.CreateWebLink(rect, url);

            Annotations.Add(annotation);
            return(annotation);
        }
Beispiel #7
0
        public virtual void Test06()
        {
            String      outFile  = destinationFolder + "parentTreeTest06.pdf";
            String      cmpFile  = sourceFolder + "cmp_parentTreeTest06.pdf";
            PdfDocument document = new PdfDocument(new PdfWriter(outFile));

            document.SetTagged();
            PdfStructElem doc       = document.GetStructTreeRoot().AddKid(new PdfStructElem(document, PdfName.Document));
            PdfPage       firstPage = document.AddNewPage();
            PdfCanvas     canvas    = new PdfCanvas(firstPage);

            canvas.BeginText();
            canvas.SetFontAndSize(PdfFontFactory.CreateFont(StandardFonts.COURIER), 24);
            canvas.SetTextMatrix(1, 0, 0, 1, 32, 512);
            PdfStructElem paragraph = doc.AddKid(new PdfStructElem(document, PdfName.P));
            PdfStructElem span1     = paragraph.AddKid(new PdfStructElem(document, PdfName.Span, firstPage));

            canvas.OpenTag(new CanvasTag(span1.AddKid(new PdfMcrNumber(firstPage, span1))));
            canvas.ShowText("Hello ");
            canvas.CloseTag();
            canvas.OpenTag(new CanvasTag(span1.AddKid(new PdfMcrDictionary(firstPage, span1))));
            canvas.ShowText("World");
            canvas.CloseTag();
            canvas.EndText();
            canvas.Release();
            PdfPage           secondPage       = document.AddNewPage();
            PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15));

            secondPage.AddAnnotation(linkExplicitDest);
            document.Close();
            NUnit.Framework.Assert.IsTrue(CheckParentTree(outFile, cmpFile));
        }
        private MemoryStream CreatePdfWithGoToAnnot(bool isTheSameLink, bool diffDisplayOptions)
        {
            MemoryStream stream      = new MemoryStream();
            PdfDocument  pdfDocument = new PdfDocument(new PdfWriter(stream));

            pdfDocument.AddNewPage();
            pdfDocument.AddNewPage();
            pdfDocument.AddNewPage();
            Rectangle linkLocation             = new Rectangle(523, 770, 36, 36);
            PdfExplicitDestination destination = PdfExplicitDestination.CreateFit(pdfDocument.GetPage(3));
            PdfAnnotation          annotation  = new PdfLinkAnnotation(linkLocation).SetAction(PdfAction.CreateGoTo(destination)
                                                                                               ).SetBorder(new PdfArray(new int[] { 0, 0, 1 }));

            pdfDocument.GetFirstPage().AddAnnotation(annotation);
            if (!isTheSameLink)
            {
                destination = (diffDisplayOptions) ? PdfExplicitDestination.Create(pdfDocument.GetPage(3), PdfName.XYZ, 350
                                                                                   , 350, 0, 0, 1) : PdfExplicitDestination.CreateFit(pdfDocument.GetPage(1));
            }
            annotation = new PdfLinkAnnotation(linkLocation).SetAction(PdfAction.CreateGoTo(destination)).SetBorder(new
                                                                                                                    PdfArray(new int[] { 0, 0, 1 }));
            pdfDocument.GetPage(2).AddAnnotation(annotation);
            pdfDocument.Close();
            return(stream);
        }
Beispiel #9
0
        /// <summary>
        /// Adds an intra document link.
        /// </summary>
        /// <param name="rect">The rect.</param>
        /// <param name="destinationPage">The destination page.</param>
        public PdfLinkAnnotation AddDocumentLink(PdfRectangle rect, int destinationPage)
        {
            PdfLinkAnnotation annotation = PdfLinkAnnotation.CreateDocumentLink(rect, destinationPage);

            Annotations.Add(annotation);
            return(annotation);
        }
Beispiel #10
0
        /// <summary>
        /// Adds an external embedded document link.
        /// </summary>
        /// <param name="rect">The link area in default page coordinates.</param>
        /// <param name="documentPath">The path to the target document.</param>
        /// <param name="destinationPath">The path to the named destination through the embedded documents in the target document.
        /// The path is separated by '\' and the last segment is the name of the named destination.
        /// The other segments describe the route from the root document to the embedded document.
        /// Each segment name refers to a child with this name in the EmbeddedFiles name dictionary.</param>
        /// <param name="newWindow">True, if the destination document shall be opened in a new window.
        /// If not set, the viewer application should behave in accordance with the current user preference.</param>
        public PdfLinkAnnotation AddEmbeddedDocumentLink(PdfRectangle rect, string documentPath, string destinationPath, bool?newWindow = null)
        {
            PdfLinkAnnotation annotation = PdfLinkAnnotation.CreateEmbeddedDocumentLink(rect, documentPath, destinationPath, newWindow);

            Annotations.Add(annotation);
            return(annotation);
        }
Beispiel #11
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));

            int[]          borders        = new int[] { 0, 0, 1 };
            PdfDestination pdfDestination = PdfExplicitDestination.CreateFit(pdfDoc.GetPage(10));
            Rectangle      rect           = new Rectangle(0, 806, 595, 36);
            PdfAnnotation  a10            = new PdfLinkAnnotation(rect)
                                            .SetAction(PdfAction.CreateGoTo(pdfDestination))
                                            .SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT)
                                            .SetPage(pdfDoc.GetPage(10)).SetBorder(new PdfArray(borders))
                                            .SetColor(new PdfArray(new float[] { 0, 1, 0 }));

            pdfDoc.GetPage(1).AddAnnotation(a10);
            PdfDestination d2 = PdfExplicitDestination.CreateFit(pdfDoc.GetPage(1));
            PdfAnnotation  a1 = new PdfLinkAnnotation(rect)
                                .SetAction(PdfAction.CreateGoTo(d2))
                                .SetHighlightMode(PdfAnnotation.HIGHLIGHT_PUSH)
                                .SetPage(pdfDoc.GetPage(1))
                                .SetBorder(new PdfArray(borders))
                                .SetColor(new PdfArray(new float[] { 0, 1, 0 }));

            pdfDoc.GetPage(10).AddAnnotation(a1);

            pdfDoc.Close();
        }
Beispiel #12
0
        private static void CreateLaunchActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Launch actions:", font, blackBrush, 400, 360);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 380, 200, 20);
                slo.X = 500;
                slo.Y = 390;
                document.Pages[i].Graphics.DrawString("Launch samples explorer", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 380, 200, 20);

                // Create a launch action and attach it to the link.
                PdfLaunchAction launchAction = new PdfLaunchAction();
                launchAction.FileName = "Xfinium.Pdf.SamplesExplorer.Win.exe";
                link.Action           = launchAction;
            }
        }
Beispiel #13
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();
        }
Beispiel #14
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_"
                                                                             ));
        }
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfAnnotation annotation = new PdfLinkAnnotation(GetOccupiedAreaBBox())
                                           .SetAction(PdfAction.CreateURI("https://lowagie.com/bio"));

                drawContext.GetDocument().GetLastPage().AddAnnotation(annotation);
            }
            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);
            }
Beispiel #17
0
        public static void AddAnnotationToPDF()
        {
            // Create a new PDF document.
            PdfDocument document = new PdfDocument();

            // Create a page.
            PdfPage page = document.AddPage();

            // Get current page graphics
            XGraphics g = XGraphics.FromPdfPage(page);

            // Create a PDF text annotation.
            PdfTextAnnotation textAnnot = new PdfTextAnnotation();

            textAnnot.Title    = "Title sample";
            textAnnot.Subject  = "Subject sample";
            textAnnot.Contents = "This is the first line of annotation.\rThis is the 2nd line.";
            textAnnot.Icon     = PdfTextAnnotationIcon.Comment;

            // Convert rectangle from world space to page space(visual to graphics drawing). This is necessary because
            // the annotation is placed relative to the bottom left corner of the page with units measured in point.
            XRect rect = g.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 60), new XSize(50, 50)));

            textAnnot.Rectangle = new PdfRectangle(rect);

            // Add the annotation to the page
            page.Annotations.Add(textAnnot);


            // Create a PDF rubber stamp annotation.
            PdfRubberStampAnnotation rsAnnot = new PdfRubberStampAnnotation();

            rsAnnot.Icon = PdfRubberStampAnnotationIcon.Approved;

            rect = g.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 200), new XSize(300, 150)));
            rsAnnot.Rectangle = new PdfRectangle(rect);

            // Add the rubber stamp annotation to the page.
            page.Annotations.Add(rsAnnot);


            // Create a PDF link annotation
            rect = g.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 400), new XSize(300, 150)));
            PdfLinkAnnotation linkAnnot = PdfLinkAnnotation.CreateWebLink(new PdfRectangle(rect), "http://www.xspdf.com");

            page.Annotations.Add(linkAnnot);


            // Save and show the document
            document.Save("Annotations.pdf");
            Process.Start("Annotations.pdf");
        }
        /**************************************************************************/

        public List <KeyValuePair <string, string> > GetOutLinks()
        {
            int TotalPages = this.Pdf.GetNumberOfPages();
            List <KeyValuePair <string, string> > OutLinks = new List <KeyValuePair <string, string> >(TotalPages);

            for (int i = 1; i <= TotalPages; i++)
            {
                PdfPage Page             = this.Pdf.GetPage(i);
                int     AnnotationsCount = Page.GetAnnotations().Count;

                if (AnnotationsCount > 0)
                {
                    IList <PdfAnnotation> Annotations = Page.GetAnnotations();

                    foreach (PdfAnnotation Annotation in Annotations)
                    {
                        if (Annotation.GetSubtype().Equals(PdfName.Link))
                        {
                            PdfLinkAnnotation LinkAnnotation = (PdfLinkAnnotation)Annotation;

                            if (LinkAnnotation.GetAction().Get(PdfName.URI) != null)
                            {
                                string Url = LinkAnnotation.GetAction().Get(PdfName.URI).ToString();

                                if ((!string.IsNullOrEmpty(Url)) && (!string.IsNullOrWhiteSpace(Url)))
                                {
                                    try
                                    {
                                        Uri ParsedUri = new Uri(Url);
                                        if (ParsedUri.Scheme.ToLower().Equals("http") || ParsedUri.Scheme.ToLower().Equals("https"))
                                        {
                                            KeyValuePair <string, string> LinkPair = new KeyValuePair <string, string>(
                                                LinkAnnotation.GetAction().Get(PdfName.URI).ToString(),
                                                "PDF Annotation Link"
                                                );
                                            OutLinks.Add(LinkPair);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        this.DebugMsg(ex.Message);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(OutLinks);
        }
Beispiel #19
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();
        }
Beispiel #20
0
        static public void UpdateDoc(PdfDocument doc, Dictionary <string, int> url2pagoffset, string pagtitle, int pag0len)
        {
            PdfString uri;

            for (int ipag = 0; ipag < doc.PageCount; ipag++)
            {
                PdfPage outpage = doc.Pages[ipag];

                for (int ianot = 0; ianot < outpage.Annotations.Count; ianot++)
                {
                    PdfAnnotation anot = outpage.Annotations[ianot] as PdfAnnotation;

                    foreach (PdfDictionary dicitem in anot.Elements.Values.OfType <PdfDictionary> ( ))
                    {
                        if ((uri = dicitem.Elements["/URI"] as PdfString) != null)
                        {
                            foreach (string urikey in url2pagoffset.Keys)
                            {
                                Uri    test = null;
                                string urikey2;
                                try
                                {
                                    urikey2 = RemoveEscEtc(urikey);

                                    if (Uri.TryCreate(urikey2, UriKind.Absolute, out test))
                                    {
                                        if (URICompare(uri.Value, urikey2))
                                        {
                                            PdfRectangle rect    = anot.Rectangle as PdfRectangle;
                                            PdfRectangle newrect = rect.Clone( );

                                            int pagnumb = url2pagoffset[urikey] + pag0len;
                                            PdfLinkAnnotation linkanot = outpage.AddDocumentLink(newrect, pagnumb);

                                            linkanot.Title  = pagtitle;
                                            linkanot.Title += " (page " + pagnumb.ToString( ) + ")";

                                            anot.Rectangle = new PdfRectangle(new XRect(0d, 0d, 0d, 0d));
                                        }
                                    }
                                }
                                catch (Exception)
                                { }
                            }
                        }
                    }
                }
            }
        }
Beispiel #21
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_"
                                                                             ));
        }
Beispiel #22
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_"
                                                                             ));
        }
Beispiel #23
0
        public virtual void LinkAnnotationOnDivSplitTest01()
        {
            String            outFileName = destinationFolder + "linkAnnotationOnDivSplitTest01.pdf";
            String            cmpFileName = sourceFolder + "cmp_linkAnnotationOnDivSplitTest01.pdf";
            PdfDocument       pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document          doc         = new Document(pdfDocument);
            PdfAction         action      = PdfAction.CreateURI("http://itextpdf.com");
            PdfLinkAnnotation annotation  = new PdfLinkAnnotation(new Rectangle(1, 1)).SetAction(action);
            Div div = new Div().SetHeight(2000).SetBackgroundColor(ColorConstants.RED);

            div.SetProperty(Property.LINK_ANNOTATION, annotation);
            doc.Add(div);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             ));
        }
Beispiel #24
0
        public virtual void CreatePdf(String dest)
        {
            //Initialize PDF document
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            //Initialize document
            Document document = new Document(pdf);
            //Create link annotation
            PdfLinkAnnotation annotation = ((PdfLinkAnnotation) new PdfLinkAnnotation(new Rectangle(0, 0)).SetAction(PdfAction
                                                                                                                     .CreateURI("http://itextpdf.com/")));
            Link      link = new Link("here", annotation);
            Paragraph p    = new Paragraph("The example of link annotation. Click ").Add(link.SetUnderline()).Add(" to learn more..."
                                                                                                                  );

            document.Add(p);
            //Close document
            document.Close();
        }
Beispiel #25
0
        public virtual void SplitLinkTest01()
        {
            String            outFileName = destinationFolder + "splitLinkTest01.pdf";
            String            cmpFileName = sourceFolder + "cmp_splitLinkTest01.pdf";
            PdfDocument       pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document          doc         = new Document(pdfDocument);
            PdfAction         action      = PdfAction.CreateURI("http://itextpdf.com");
            PdfLinkAnnotation annotation  = new PdfLinkAnnotation(new Rectangle(1, 1)).SetAction(action);
            Link linkByAnnotation         = new Link(LONG_TEXT, annotation);

            doc.Add(new Div().SetHeight(700).SetBackgroundColor(ColorConstants.RED));
            // This paragraph is so long that it will be present on the first, second and third pages
            doc.Add(new Paragraph(linkByAnnotation));
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             ));
        }
Beispiel #26
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_"
                                                                             ));
        }
Beispiel #27
0
        private static void CreateRemoteGoToActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen   blackPen   = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();

            sao.Brush = blackBrush;
            sao.Font  = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();

            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign   = PdfStringVerticalAlign.Middle;

            Random rnd = new Random();

            for (int i = 0; i < document.Pages.Count; i++)
            {
                int destinationPage = rnd.Next(document.Pages.Count);

                document.Pages[i].Graphics.DrawString("Go To Remote actions:", font, blackBrush, 400, 300);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 320, 200, 20);
                slo.X = 500;
                slo.Y = 330;
                document.Pages[i].Graphics.DrawString("Go To page " + (destinationPage + 1).ToString() + " in sample.pdf", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 320, 200, 20);

                // Create a GoToR action and attach it to the link.
                PdfPageNumberDestination pageDestination = new PdfPageNumberDestination();
                pageDestination.PageNumber = destinationPage;
                pageDestination.Left       = 0;
                pageDestination.Top        = 792;
                pageDestination.Zoom       = 0; // Keep current zoom
                PdfRemoteGoToAction remoteGoToAction = new PdfRemoteGoToAction();
                remoteGoToAction.FileName    = "sample.pdf";
                remoteGoToAction.Destination = pageDestination;
                link.Action = remoteGoToAction;
            }
        }
        public virtual void StructElemTest05()
        {
            FileStream fos    = new FileStream(destinationFolder + "structElemTest05.pdf", FileMode.Create);
            PdfWriter  writer = new PdfWriter(fos);

            writer.SetCompressionLevel(CompressionConstants.NO_COMPRESSION);
            PdfDocument document = new PdfDocument(writer);

            document.SetTagged();
            PdfStructElem doc    = document.GetStructTreeRoot().AddKid(new PdfStructElem(document, PdfName.Document));
            PdfPage       page   = document.AddNewPage();
            PdfCanvas     canvas = new PdfCanvas(page);

            canvas.BeginText();
            canvas.SetFontAndSize(PdfFontFactory.CreateFont(FontConstants.COURIER), 14);
            canvas.SetTextMatrix(1, 0, 0, 1, 32, 512);
            PdfStructElem paragraph = doc.AddKid(new PdfStructElem(document, PdfName.P));
            PdfStructElem span1     = paragraph.AddKid(new PdfStructElem(document, PdfName.Span, page));

            canvas.OpenTag(new CanvasTag(span1.AddKid(new PdfMcrNumber(page, span1))));
            canvas.ShowText("Click ");
            canvas.CloseTag();
            PdfStructElem link = paragraph.AddKid(new PdfStructElem(document, PdfName.Link, page));

            canvas.OpenTag(new CanvasTag(link.AddKid(new PdfMcrNumber(page, link))));
            canvas.SetFillColorRgb(0, 0, 1).ShowText("here");
            PdfLinkAnnotation linkAnnotation = new PdfLinkAnnotation(new Rectangle(80, 508, 40, 18));

            linkAnnotation.SetColor(new float[] { 0, 0, 1 }).SetBorder(new PdfArray(new float[] { 0, 0, 1 }));
            page.AddAnnotation(-1, linkAnnotation, false);
            link.AddKid(new PdfObjRef(linkAnnotation, link));
            canvas.CloseTag();
            PdfStructElem span2 = paragraph.AddKid(new PdfStructElem(document, PdfName.Span, page));

            canvas.OpenTag(new CanvasTag(span2.AddKid(new PdfMcrNumber(page, span2))));
            canvas.SetFillColorRgb(0, 0, 0);
            canvas.ShowText(" to visit iText site.");
            canvas.CloseTag();
            canvas.EndText();
            canvas.Release();
            document.Close();
            CompareResult("structElemTest05.pdf", "cmp_structElemTest05.pdf", "diff_structElem_05_");
        }
        public virtual void CreatePdf(String dest)
        {
            PdfDocument   pdf      = new PdfDocument(new PdfWriter(dest));
            Document      document = new Document(pdf);
            PdfAction     js       = PdfAction.CreateJavaScript("app.alert('Boo!');");
            PdfAnnotation la1      = ((PdfLinkAnnotation) new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).SetHighlightMode(
                                          PdfAnnotation.HIGHLIGHT_INVERT).SetAction(js)).SetBorderStyle(PdfAnnotation.STYLE_UNDERLINE);
            Link link1 = new Link("here", (PdfLinkAnnotation)la1);

            document.Add(new Paragraph().Add("Click ").Add(link1).Add(" if you want to be scared."));
            PdfAnnotation la2 = new PdfLinkAnnotation(new Rectangle(0, 0, 0, 0)).SetDestination(PdfExplicitDestination
                                                                                                .CreateFit(2)).SetHighlightMode(PdfAnnotation.HIGHLIGHT_PUSH).SetBorderStyle(PdfAnnotation.STYLE_INSET
                                                                                                                                                                             );
            Link link2 = new Link("next page", (PdfLinkAnnotation)la2);

            document.Add(new Paragraph().Add("Go to the ").Add(link2).Add(" if you're too scared."));
            document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE));
            document.Add(new Paragraph().Add("There, there, everything is OK."));
            document.Close();
        }
        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);
            }
        }
Beispiel #31
0
        private static void CreateJavaScriptActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("JavaScript actions:", font, blackBrush, 400, 480);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 500, 200, 20);
                slo.X = 500;
                slo.Y = 510;
                document.Pages[i].Graphics.DrawString("Click me", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 500, 200, 20);

                // Create a Javascript action and attach it to the link.
                PdfJavaScriptAction jsAction = new PdfJavaScriptAction();
                jsAction.Script = "app.alert({cMsg: \"JavaScript action: you are now on page " + (i + 1) + "\", cTitle: \"Xfinium.Pdf Actions Sample\"});";
                link.Action = jsAction;
            }
        }
Beispiel #32
0
        private static void CreateLaunchActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Launch actions:", font, blackBrush, 400, 360);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 380, 200, 20);
                slo.X = 500;
                slo.Y = 390;
                document.Pages[i].Graphics.DrawString("Launch samples explorer", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 380, 200, 20);

                // Create a launch action and attach it to the link.
                PdfLaunchAction launchAction = new PdfLaunchAction();
                launchAction.FileName = "Xfinium.Pdf.SamplesExplorer.Win.exe";
                link.Action = launchAction;
            }
        }
Beispiel #33
0
        private static void CreateNamedActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Named actions:", font, blackBrush, 400, 20);

                /////////////
                // First page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 40, 200, 20);
                slo.X = 500;
                slo.Y = 50;
                document.Pages[i].Graphics.DrawString("Go To First Page", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 40, 200, 20);

                // Create a named action and attach it to the link.
                PdfNamedAction namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.FirstPage;
                link.Action = namedAction;

                /////////////
                // Prev page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 80, 200, 20);
                slo.Y = 90;
                document.Pages[i].Graphics.DrawString("Go To Previous Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 80, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.PrevPage;
                link.Action = namedAction;

                /////////////
                // Next page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 120, 200, 20);
                slo.Y = 130;
                document.Pages[i].Graphics.DrawString("Go To Next Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 120, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.NextPage;
                link.Action = namedAction;

                /////////////
                // Last page
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 160, 200, 20);
                slo.Y = 170;
                document.Pages[i].Graphics.DrawString("Go To Last Page", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 160, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.LastPage;
                link.Action = namedAction;

                /////////////
                // Print document
                /////////////
                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 200, 200, 20);
                slo.Y = 210;
                document.Pages[i].Graphics.DrawString("Print Document", sao, slo);

                // Create a link annotation on top of the widget.
                link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 200, 200, 20);

                // Create a named action and attach it to the link.
                namedAction = new PdfNamedAction();
                namedAction.NamedAction = PdfActionName.Print;
                link.Action = namedAction;
            }
        }
Beispiel #34
0
        private static void CreateUriActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            for (int i = 0; i < document.Pages.Count; i++)
            {
                document.Pages[i].Graphics.DrawString("Uri actions:", font, blackBrush, 400, 420);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 440, 200, 20);
                slo.X = 500;
                slo.Y = 450;
                document.Pages[i].Graphics.DrawString("Go to xfiniumpdf.com", sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 440, 200, 20);

                // Create an uri action and attach it to the link.
                PdfUriAction uriAction = new PdfUriAction();
                uriAction.URI = "http://www.xfiniumpdf.com";
                link.Action = uriAction;
            }
        }
Beispiel #35
0
        private static void CreateGoToActions(PdfFixedDocument document, PdfFont font)
        {
            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);
            PdfBrush blackBrush = new PdfBrush();

            font.Size = 12;
            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Brush = blackBrush;
            sao.Font = font;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            Random rnd = new Random();
            for (int i = 0; i < document.Pages.Count; i++)
            {
                int destinationPage = rnd.Next(document.Pages.Count);

                document.Pages[i].Graphics.DrawString("Go To actions:", font, blackBrush, 400, 240);

                document.Pages[i].Graphics.DrawRectangle(blackPen, 400, 260, 200, 20);
                slo.X = 500;
                slo.Y = 270;
                document.Pages[i].Graphics.DrawString("Go To page: " + (destinationPage + 1).ToString(), sao, slo);

                // Create a link annotation on top of the widget.
                PdfLinkAnnotation link = new PdfLinkAnnotation();
                document.Pages[i].Annotations.Add(link);
                link.VisualRectangle = new PdfVisualRectangle(400, 260, 200, 20);

                // Create a GoTo action and attach it to the link.
                PdfPageDirectDestination pageDestination = new PdfPageDirectDestination();
                pageDestination.Page = document.Pages[destinationPage];
                pageDestination.Left = 0;
                pageDestination.Top = 0;
                pageDestination.Zoom = 0; // Keep current zoom
                PdfGoToAction gotoPageAction = new PdfGoToAction();
                gotoPageAction.Destination = pageDestination;
                link.Action = gotoPageAction;
            }
        }
Beispiel #36
0
        private static void Create3DAnnotations(PdfFixedDocument document, PdfFont font, Stream u3dStream)
        {
            PdfBrush blackBrush = new PdfBrush();

            PdfPage page = document.Pages.Add();
            page.Rotation = 90;

            page.Graphics.DrawString("3D annotations", font, blackBrush, 50, 50);

            byte[] u3dContent = new byte[u3dStream.Length];
            u3dStream.Read(u3dContent, 0, u3dContent.Length);

            Pdf3DView view0 = new Pdf3DView();
            view0.CameraToWorldMatrix = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 };
            view0.CenterOfOrbit = 0.123106;
            view0.ExternalName = "Default";
            view0.InternalName = "Default";
            view0.Projection = new Pdf3DProjection();
            view0.Projection.FieldOfView = 30;

            Pdf3DView view1 = new Pdf3DView();
            view1.CameraToWorldMatrix = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 };
            view1.CenterOfOrbit = 0.123106;
            view1.ExternalName = "Top";
            view1.InternalName = "Top";
            view1.Projection = new Pdf3DProjection();
            view1.Projection.FieldOfView = 14.8096;

            Pdf3DView view2 = new Pdf3DView();
            view2.CameraToWorldMatrix = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 };
            view2.CenterOfOrbit = 0.123106;
            view2.ExternalName = "Side";
            view2.InternalName = "Side";
            view2.Projection = new Pdf3DProjection();
            view2.Projection.FieldOfView = 12.3794;

            Pdf3DView view3 = new Pdf3DView();
            view3.CameraToWorldMatrix = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 };
            view3.CenterOfOrbit = 0.123106;
            view3.ExternalName = "Isometric";
            view3.InternalName = "Isometric";
            view3.Projection = new Pdf3DProjection();
            view3.Projection.FieldOfView = 15.1226;

            Pdf3DView view4 = new Pdf3DView();
            view4.CameraToWorldMatrix = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 };
            view4.CenterOfOrbit = 0.123106;
            view4.ExternalName = "Front";
            view4.InternalName = "Front";
            view4.Projection = new Pdf3DProjection();
            view4.Projection.FieldOfView = 15.1226;

            Pdf3DView view5 = new Pdf3DView();
            view5.CameraToWorldMatrix = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 };
            view5.CenterOfOrbit = 0.123106;
            view5.ExternalName = "Back";
            view5.InternalName = "Back";
            view5.Projection = new Pdf3DProjection();
            view5.Projection.FieldOfView = 12.3794;

            Pdf3DStream _3dStream = new Pdf3DStream();
            _3dStream.Views.Add(view0);
            _3dStream.Views.Add(view1);
            _3dStream.Views.Add(view2);
            _3dStream.Views.Add(view3);
            _3dStream.Views.Add(view4);
            _3dStream.Views.Add(view5);
            _3dStream.Content = u3dContent;
            _3dStream.DefaultViewIndex = 0;
            Pdf3DAnnotation _3da = new Pdf3DAnnotation();
            _3da.Stream = _3dStream;

            PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(200, 200);
            appearance.Graphics.DrawString("Click to activate", font, blackBrush, 50, 50);
            _3da.NormalAppearance = appearance;

            page.Annotations.Add(_3da);
            _3da.VisualRectangle = new PdfVisualRectangle(36, 36, 720, 540);

            PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
            sao.Font = font;
            sao.Brush = blackBrush;
            PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
            slo.Y = 585 + 18 / 2;
            slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
            slo.VerticalAlign = PdfStringVerticalAlign.Middle;

            PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1);

            page.Graphics.DrawRectangle(blackPen, 50, 585, 120, 18);
            slo.X = 50 + 120 / 2;
            page.Graphics.DrawString("Top", sao, slo);

            PdfGoTo3DViewAction gotoTopView = new PdfGoTo3DViewAction();
            gotoTopView.ViewIndex = 1;
            gotoTopView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoTopView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoTopView);
            linkGotoTopView.VisualRectangle = new PdfVisualRectangle(50, 585, 120, 18);
            linkGotoTopView.Action = gotoTopView;

            page.Graphics.DrawRectangle(blackPen, 190, 585, 120, 18);
            slo.X = 190 + 120 / 2;
            page.Graphics.DrawString("Side", sao, slo);

            PdfGoTo3DViewAction gotoSideView = new PdfGoTo3DViewAction();
            gotoSideView.ViewIndex = 2;
            gotoSideView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoSideView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoSideView);
            linkGotoSideView.VisualRectangle = new PdfVisualRectangle(190, 585, 120, 18);
            linkGotoSideView.Action = gotoSideView;

            page.Graphics.DrawRectangle(blackPen, 330, 585, 120, 18);
            slo.X = 330 + 120 / 2;
            page.Graphics.DrawString("Isometric", sao, slo);

            PdfGoTo3DViewAction gotoIsometricView = new PdfGoTo3DViewAction();
            gotoIsometricView.ViewIndex = 3;
            gotoIsometricView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoIsometricView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoIsometricView);
            linkGotoIsometricView.VisualRectangle = new PdfVisualRectangle(330, 585, 120, 18);
            linkGotoIsometricView.Action = gotoIsometricView;

            page.Graphics.DrawRectangle(blackPen, 470, 585, 120, 18);
            slo.X = 470 + 120 / 2;
            page.Graphics.DrawString("Front", sao, slo);

            PdfGoTo3DViewAction gotoFrontView = new PdfGoTo3DViewAction();
            gotoFrontView.ViewIndex = 4;
            gotoFrontView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoFrontView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoFrontView);
            linkGotoFrontView.VisualRectangle = new PdfVisualRectangle(470, 585, 120, 18);
            linkGotoFrontView.Action = gotoFrontView;

            page.Graphics.DrawRectangle(blackPen, 610, 585, 120, 18);
            slo.X = 610 + 120 / 2;
            page.Graphics.DrawString("Back", sao, slo);

            PdfGoTo3DViewAction gotoBackView = new PdfGoTo3DViewAction();
            gotoBackView.ViewIndex = 5;
            gotoBackView.TargetAnnotation = _3da;
            PdfLinkAnnotation linkGotoBackView = new PdfLinkAnnotation();
            page.Annotations.Add(linkGotoBackView);
            linkGotoBackView.VisualRectangle = new PdfVisualRectangle(610, 585, 120, 18);
            linkGotoBackView.Action = gotoBackView;
        }