Bookmarks and Hyperlinks

Bookmarks are used to record a location in a document and hyperlinks are used to jump to a recorded location or to an external content.

Following sample demonstrates how to insert a bookmark to a document and a hyperlink that links to a bookmark.

Screenshot

Bookmarks and Hyperlinks Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.IO;
3using System.Linq;
4using GemBox.Document;
5using GemBox.Document.Drawing;
6
7class Sample
8{
9    [STAThread]
10    static void Main(string[] args)
11    {
12        // If using Professional version, put your serial key below.
13        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
14
15        DocumentModel document = new DocumentModel();
16
17        string bookmarkName = "LinkToTop";
18
19        document.Sections.Add(
20            new Section(document,
21                new Paragraph(document,
22                    new BookmarkStart(document, bookmarkName),
23                    new Run(document, "GemBox.Document"),
24                    new BookmarkEnd(document, bookmarkName)),
25                new Paragraph(document,
26                    new Hyperlink(document, "http://www.gemboxsoftware.com/document/overview", "GemBox.Document"),
27                    new Run(document, " is a .NET component that enables developers to read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, RTF and TXT) from .NET applications in a simple and efficient way.")),
28                 new Paragraph(document),
29                 new Paragraph(document),
30                 new Paragraph(document),
31                 new Paragraph(document,
32            // When user clicks on this link it will jump to the text between BookmarkStart and BookmarkEnd.
33                     new Hyperlink(document, bookmarkName, "To Top")
34                     {
35                         IsBookmarkLink = true
36                     })));
37
38        document.Save("Bookmarks and Hyperlinks.docx");
39    }
40}
1Imports System
2Imports System.IO
3Imports System.Linq
4Imports GemBox.Document
5Imports GemBox.Document.Drawing
6
7Module Samples
8
9    Sub Main()
10
11        ' If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
13
14        Dim document As DocumentModel = New DocumentModel
15
16        Dim bookmarkName As String = "LinkToTop"
17
18        ' When user clicks on this link it will jump to the text between BookmarkStart and BookmarkEnd. 
19        document.Sections.Add(
20            New Section(document,
21                New Paragraph(document,
22                    New BookmarkStart(document, bookmarkName),
23                    New Run(document, "GemBox.Document"),
24                    New BookmarkEnd(document, bookmarkName)),
25                New Paragraph(document,
26                    New Hyperlink(document, "http://www.gemboxsoftware.com/document/overview", "GemBox.Document"),
27                    New Run(document, " is a .NET component that enables developers to read, write, convert and print document files (DOCX, DOC, PDF, HTML, XPS, RTF and TXT) from .NET applications in a simple and efficient way.")),
28                New Paragraph(document),
29                New Paragraph(document),
30                New Paragraph(document),
31             New Paragraph(document,
32                 New Hyperlink(document, bookmarkName, "To Top") With {
33        .IsBookmarkLink = True
34                })))
35
36        document.Save("Bookmarks and Hyperlinks.docx")
37
38    End Sub
39
40End Module

Check next sample or find out more about GemBox.Document and GemBox Software.