[]
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.
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 GcPdf, see GcPdf sample browser.