- Document Solutions for PDF Overview
- Key Features
- Getting Started
- Product Architecture
-
Features
- Attachment
- Annotations
- Document
- Document Optimization
- Font
- Forms
- Form XObjects
- Actions
- Graphics
- Output Intents
- Images
- Incremental Update
- Linearization
- Links
- Outline
- Pages
- Layouts
- Complex Graphic Layouts
- Tables
- Security
- Digital Signature
- Soft Mask
- Stamps
- Tagged PDF
- Parse PDF Documents
- Layers
- Text
- Text Search, Replace and Delete
- Watermark
- AI Assistant
- Access Primitive and High-Level PDF Objects
- Render HTML to PDF
- Save PDF as Image
- Barcodes in PDF
- Best Practices
- Document Solutions PDF Viewer Overview
- Samples
- Walkthrough
- API Reference
- Release Notes
Links
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 2.0 (Section 12.5.6.5).
DsPdf 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:
Create an object of GcPdfDocument class.
Draw text to represent the hyperlink.
Pass the instance of LinkAnnotation class as a parameter to the Add method.
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); }
For more information about implementation of links using DsPdf, see DsPdf sample browser.