Documents for PDF .NET Edition
Features / Links
In This Topic
    Links
    In This Topic

    Among all the static content of a PDF, links are required to jump from one location to other location within the document or outside the document. Creating hyperlinks is one such way which not only helps in navigating through the content but also makes it interactive. For more information on link annotations, see PDF specification 1.7 (Section 12.5.6.5).

    GcPdf allows you to add hypertext links to a PDF document through LinkAnnotation class.

    LinksAnnotation

    Add Hyperlink

    To add a hyperlink in a PDF document, use the LinkAnnotation class. The LinkAnnotation class provides essential properties for creating a hyperlink.

    To add a hyperlink:

    1. Create an object of GcPdfDocument class.
    2. Draw text to represent the hyperlink.
    3. Pass the instance of LinkAnnotation class as a parameter to the Add method.
      C#
      Copy Code
      public void CreatePDF(Stream stream)
      {
          GcPdfDocument doc = new GcPdfDocument();
          var page = doc.NewPage();
          var g = page.Graphics;
      
          // Draw some text that will represent the link
          var tf = new TextFormat()
          {
              Font = StandardFonts.Times,
              FontSize = 14
          };
          var tl = new TextLayout();
          tl.MarginLeft = tl.MarginTop = tl.MarginRight = tl.MarginBottom = 72;
          tl.Append("Google google on the wall, please tell me all!", tf);
          tl.PerformLayout(true);
          g.DrawTextLayout(tl, PointF.Empty);
      
          // Add a link associated with the text area
          page.Annotations.Add
          (new LinkAnnotation(tl.ContentRectangle, new ActionURI("http://www.google.com")));
      
          // Done
          doc.Save(stream);
      }
      
    Back to Top

    For more information about implementation of links using GcPdf, see GcPdf sample browser.