Skip to main content
A newer version of this page is available. .

How to: Add a Link to a Page

  • 2 minutes to read

Important

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.

This example shows how to add a link to a page using the PDF Document Creation API.

Note

The measurement unit of X, Y destination coordinates is equal to 1/72 of an inch.

using DevExpress.Pdf;
using System.Drawing;


namespace AddLinkToPage {
    class Program {
        static void Main(string[] args) {
            using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {

                // Create an empty document.
                processor.CreateEmptyDocument("..\\..\\Result.pdf");

                // Create and draw graphics.
                using (PdfGraphics graphics = processor.CreateGraphics()) {
                    DrawGraphics(graphics);

                    // Create a link to a page specifying link area, the page number and X, Y destinations.
                    graphics.AddLinkToPage(new RectangleF(180, 160, 480, 30), 1, 168, 230);

                    // Render a page with graphics.
                    processor.RenderNewPage(PdfPaperSize.Letter, graphics);
                }
            }
        }

        static void DrawGraphics(PdfGraphics graphics) {

            // Draw a text line on the page. 
            SolidBrush black = (SolidBrush)Brushes.Black;
            using (Font font = new Font("Times New Roman", 32, FontStyle.Bold)) {
                graphics.DrawString("PDF Document Processor", font, black, 180, 150);
            }
        }
    }
}
See Also