Skip to content
Links and Navigation

Links and Navigation

Getting a reader from one place to another uses two mechanisms that work together. A bookmark names a location; a hyperlink points at a name or at a URL. Neither is much use without the other when the target is inside the same document.

Bookmarks belong to a paragraph. Paragraph.AddBookmark writes a start and an end marker with nothing between them and allocates a fresh numeric ID on every call, so the name is the only handle worth holding onto. Document.Bookmarks and Document.BookmarkByName find them again, and the Bookmark value they return can read the text of the range and the paragraphs it touches.

Hyperlinks belong to a paragraph too, and the target decides how they are stored. SetTarget adds a relationship pointing at an external URL; SetTargetBookmark stores a bookmark name as an anchor and no relationship at all. The two setters clear each other, so a link is one or the other. Neither one styles the link: a document from document.New() has no Hyperlink character style, and a link run that doesn’t ask for one renders as ordinary body text.

A table of contents is a different mechanism again. It is a Word field, so UniOffice writes the instruction and the application computes the entries when it opens the file. Nothing is cached in between, which means the contents page is blank until Word or LibreOffice refreshes the field, and the native DOCX to PDF converter, which evaluates PAGE, NUMPAGES and REF but not TOC, produces a blank contents page as well.

Where to look

GuideCovers
HyperlinksExternal and internal links, and the character style that makes them look like links.
BookmarksNaming a location, enumerating bookmarks, and looking one up.
Table of ContentsThe TOC field, and what the document holds before it is refreshed.
Custom Table of ContentsTOCOptions: hyperlinked entries, no page numbers, a heading range.
Last updated on