Outlines
Outlines are what a PDF viewer shows as bookmarks: a tree of titles, each pointing
at a place in the document. UniPDF models them at two levels. PdfOutlineTreeNode
is the PDF structure itself, a doubly linked list of siblings with parent and child
pointers. model.Outline and model.OutlineItem are the high-level view: a slice
of entries, each with a title, a destination, and its own entries. Work with the
high-level types and let ToOutlineTree build the linked list.
outline := model.NewOutline()
outline.Add(model.NewOutlineItem("Chapter 1", model.NewOutlineDest(0, 0, 792)))
pdfWriter.AddOutlineTree(outline.ToOutlineTree())The Outline container holds only its top level entries. Everything else belongs
to the item: its title, its destination, and its children. There is no separate
node type for a nested bookmark, so the structure is uniform however deep it goes.
A destination is an OutlineDest with a page index, a mode and up to three
coordinates. The page index is zero-based. The mode is the PDF destination type,
XYZ for an explicit position and the Fit variants for viewer-chosen zoom, and
it determines which coordinates are used.
Both types carry JSON tags, which is what makes the outlines of a document portable: read them, marshal to a file, edit it, apply it to another document. That round trip is what the two guides below cover.
Where to look
| Guide | Covers |
|---|---|
| Get outlines | Reading a document’s bookmarks and writing them out as JSON. |
| Set outlines | Applying a bookmark tree to a document, and building one in code. |
An outline is navigation metadata and is not drawn on the page. If you want a
visible, clickable table of contents in the page content, that is the creator
package’s table of contents rather than an outline.