Ejemplo n.º 1
0
        /// <summary>
        /// GoToE action
        /// </summary>
        /// <param name="pdf"></param>
        private static void EmbeddedGoToAction(PdfDocument pdf, PdfPageBase page)
        {
            //add a attachment
            PdfAttachment attachment = new PdfAttachment(@"..\..\..\..\..\..\Data\GoToAction.pdf");

            pdf.Attachments.Add(attachment);

            string          text   = "Test embedded go-to action! Click this will open the attached PDF in a new window.";
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 13f));
            float           width  = 490f;
            float           height = font.Height * 2.2f;
            RectangleF      rect   = new RectangleF(0, 100, width, height);

            page.Canvas.DrawString(text, font, PdfBrushes.Black, rect);

            //create a PdfDestination with specific page, location and 200% zoom factor
            PdfDestination dest = new PdfDestination(1, new PointF(0, 842), 2f);

            //create GoToE action with dest
            PdfEmbeddedGoToAction action     = new PdfEmbeddedGoToAction(attachment.FileName, dest, true);
            PdfActionAnnotation   annotation = new PdfActionAnnotation(rect, action);

            //add the annotation
            (page as PdfNewPage).Annotations.Add(annotation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a link to an embedded document in another document.
        /// </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 static PdfLinkAnnotation CreateEmbeddedDocumentLink(PdfRectangle rect, string documentPath, string destinationPath, bool?newWindow = null)
        {
            PdfLinkAnnotation link = new PdfLinkAnnotation();

            link._linkType = LinkType.NamedDestination;
            link.Rectangle = rect;
            link._action   = PdfEmbeddedGoToAction.CreatePdfEmbeddedGoToAction(documentPath, destinationPath, newWindow);
            return(link);
        }