GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

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 example 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.

using System;
using System.IO;
using System.Linq;
using GemBox.Document;
using GemBox.Document.Drawing;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        string bookmarkName = "LinkToTop";

        document.Sections.Add(
            new Section(document,
                new Paragraph(document,
                    new BookmarkStart(document, bookmarkName),
                    new Run(document, "GemBox.Document"),
                    new BookmarkEnd(document, bookmarkName)),
                new Paragraph(document,
                    new Hyperlink(document, "http://www.gemboxsoftware.com/document/overview", "GemBox.Document"),
                    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.")),
                 new Paragraph(document),
                 new Paragraph(document),
                 new Paragraph(document),
                 new Paragraph(document,
            // When user clicks on this link it will jump to the text between BookmarkStart and BookmarkEnd.
                     new Hyperlink(document, bookmarkName, "To Top")
                     {
                         IsBookmarkLink = true
                     })));

        document.Save("Bookmarks and Hyperlinks.docx");
    }
}
Imports System
Imports System.IO
Imports System.Linq
Imports GemBox.Document
Imports GemBox.Document.Drawing

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = New DocumentModel

        Dim bookmarkName As String = "LinkToTop"

        ' When user clicks on this link it will jump to the text between BookmarkStart and BookmarkEnd. 
        document.Sections.Add(
            New Section(document,
                New Paragraph(document,
                    New BookmarkStart(document, bookmarkName),
                    New Run(document, "GemBox.Document"),
                    New BookmarkEnd(document, bookmarkName)),
                New Paragraph(document,
                    New Hyperlink(document, "http://www.gemboxsoftware.com/document/overview", "GemBox.Document"),
                    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.")),
                New Paragraph(document),
                New Paragraph(document),
                New Paragraph(document),
             New Paragraph(document,
                 New Hyperlink(document, bookmarkName, "To Top") With {
        .IsBookmarkLink = True
                })))

        document.Save("Bookmarks and Hyperlinks.docx")

    End Sub

End Module

Check next sample.