Skip to main content

Links and Navigation

Three things decide how a reader moves through a document: the places a link can land (a block's id), the links themselves ([goto], [link] and an svg shape's link), and how the viewer opens the file (metadata.viewerPreferences). The bookmarks panel is the fourth.

A block's id​

Any block can carry an id: a name, unique in the document, with no spaces. It is what HTML's id is to a URL fragment.

Where it is usedWhat it does
[goto, id]text[/goto]jumps to the block, forward or back across pages
$global.PAGEREF.idprints the number of the page the block lands on, as "see page 12" (Globals); inside a [goto] the number is a link
file.pdf#nameddest=idevery id is a named destination: a viewer opens the file at the block when the name follows its address
viewerPreferences.openAction.idthe document opens at the block
In a DOCXevery id is a Word bookmark (Insert > Bookmark lists them), and [goto] is a hyperlink to it
{
"document": {
"metadata": { "title": "Residential lease", "lang": "en" },
"content": [
{ "p": "The tenant pays the rent set out in [goto, rent-table]the rent schedule[/goto], subject to [goto, clause-7]clause 7[/goto]." },
{ "h2": "7. Early termination", "id": "clause-7" },
{ "p": "Either party may end the lease on three months' notice. See also [goto, clause-1]clause 1[/goto]." },
{ "h2": "1. Parties", "id": "clause-1" },
{ "p": "Details of [link, https://example.com/lease-guide]our lease guide[/link] are online." },
{
"id": "rent-table",
"table": {
"widths": [1, 1],
"rows": [
[{ "th": "Period" }, { "th": "Monthly rent" }],
[{ "td": "Year 1" }, { "td": "1,250.00" }]
]
}
}
]
}
}

A [goto] naming an id no block carries is reported with a WARNING, and its text is left as plain text. Under a PDF/UA-2 or WTPDF claim every link and named destination points at the block's structure element as well as its page, as ISO 14289-2 8.8 requires.

LinkTakesWhere
[goto, id]…[/goto]a block's idany text: p, headings, list items, table cells
[link, url]…[/link]an absolute http, https or mailto URLany text
link on an svg shapethe same URLsrect, circle, ellipse, polygon, path, text, image

A [link] that runs across a page break stays one link: both pieces are clickable and open the same address. The tags, their colour and their combinations with other tags are on Actions; clickable shapes are on SVG.

Viewer preferences​

metadata.viewerPreferences says how a PDF viewer opens the document: its page layout, the panel it shows, its window and its print dialogue. Nothing on the page changes. A key left out writes nothing, so the viewer's own default applies.

KeyTakesDefaultWhat it does
pageLayoutsinglePage, oneColumn, twoColumnLeft, twoColumnRight, twoPageLeft, twoPageRightsinglePageone page at a time, one scrolling column, or two side by side with odd pages on the left or the right (twoPage… two pages at a time, twoColumn… in two columns)
pageModeuseNone, useOutlines, useThumbs, fullScreen, useAttachmentsthe outline panel when the document has bookmarks, else nonethe panel open when the document opens; fullScreen asks for full-screen mode
nonFullScreenPageModeuseNone, useOutlines, useThumbsuseNonethe panel shown on leaving full screen; read only when pageMode is fullScreen
hideToolbarbooleanfalsehides the viewer's toolbars
hideMenubarbooleanfalsehides its menu bar
hideWindowUIbooleanfalsehides scroll bars and navigation controls, leaving only the pages
fitWindowbooleanfalsesizes the window to the first page
centerWindowbooleanfalsecentres the window on the screen
displayDocTitlebooleantrue when the document has a titlethe title bar shows the title rather than the file name
printScalingnone, appDefaultappDefaultnone prints at exact size, which labels, forms and barcodes need
duplexsimplex, duplexFlipShortEdge, duplexFlipLongEdge—one-sided, or two-sided flipped on the short or the long edge
pickTrayByPDFSizeboolean—the print dialogue picks the paper tray by the page size
printPageRangepairs of first and last page, from 1—the pages the print dialogue offers: [1, 2, 5, 5] is pages 1-2 and 5
numCopiesinteger, 1 or more—the copies the print dialogue offers
enforce["printScaling"]—settings the reader may not change in the print dialogue
openActiona destination (below)the top of page 1, at the viewer's zoomthe view the document opens on

The rules that hold them together:

  • enforce needs printScaling set, and set to none: a definition that enforces appDefault, or leaves printScaling out, is refused. It is a PDF 2.0 entry: on a 1.7 file it is left out and reported, so pin metadata.pdfVersion: "2.0" (or claim a-4 or ua-2, which do).
  • displayDocTitle: false is refused under a ua-1, ua-2 or WTPDF claim: an accessible document names itself by its title (ISO 14289-1 7.1, ISO 14289-2 8.11.2).
  • pageMode: "useOutlines" with no bookmarks, or useAttachments with no attachments, opens an empty panel, and a notice says so.
  • Direction is not a key. A document whose root reads right to left (direction: rtl, or vertical lines with writingMode: verticalRl) tells the viewer its pages advance right to left by itself; with pageLayout: "twoPageLeft" an Arabic, Hebrew or vertical Japanese booklet opens as such a book is bound.

A label sheet that must print at actual size, two copies, first page only:

{
"document": {
"metadata": {
"title": "Shipping labels",
"lang": "en",
"pdfVersion": "2.0",
"viewerPreferences": {
"pageMode": "useNone",
"printScaling": "none",
"enforce": ["printScaling"],
"duplex": "simplex",
"numCopies": 2,
"printPageRange": [1, 1],
"pickTrayByPDFSize": true,
"openAction": { "page": 1, "fit": "fit" }
}
},
"content": [{ "p": "Labels" }]
}
}

A presentation that opens full screen, and shows thumbnails when the reader presses Esc:

"viewerPreferences": {
"pageMode": "fullScreen",
"nonFullScreenPageMode": "useThumbs",
"hideToolbar": true, "hideMenubar": true, "hideWindowUI": true,
"fitWindow": true, "centerWindow": true,
"duplex": "duplexFlipShortEdge",
"openAction": { "page": 1, "fit": "fitH", "top": 595.28 }
}

These settings are requests to the viewer, not guarantees: a reader may ask before it goes full screen, and a browser's built-in preview may ignore them. Open the file in a desktop PDF reader to see them.

Where the document opens: openAction​

openAction is a destination: a page, or a block's id, and how the window shows it. The coordinates are points in the page's own space, measured from its bottom-left corner.

KeyTakesWhat it does
pageinteger from 1the page to open on. One past the last opens the last, reported. Absent, page 1
ida block's idopens on the block's page with its top edge at the top of the window. Beside page, the id decides, with a notice. An id no block carries is reported and the document opens as if openAction were unset
fitxyz, fit, fitH, fitV, fitR, fitB, fitBH, fitBV (default xyz)the view (below)
leftpointsthe page's left edge in the window
toppointsthe height on the page at the window's top
bottom, rightpointsunder fitR, the rectangle's bottom and right
zoomnumber, 1 is 100%under xyz; absent or 0, the viewer's current zoom
fitThe window showsReads
xyza position at a zoomleft, top, zoom; an unset top is the page's top, or the block's
fitthe whole pagenothing
fitHthe page's full widthtop
fitVthe page's full heightleft
fitRa rectangleleft, bottom, right and top, all four required; with one missing the whole page is shown, reported
fitB, fitBH, fitBVas fit, fitH, fitV, over the bounds of what is drawn rather than the pageas their twins

A coordinate the chosen view does not read is reported and ignored. Under a PDF/UA-2 or WTPDF claim the open action must point into the structure, so it must name an id: a page alone is not written, and the warning says to set openAction.id.

{
"document": {
"metadata": {
"title": "Operator's manual",
"lang": "en",
"viewerPreferences": {
"pageLayout": "twoPageRight",
"duplex": "duplexFlipLongEdge",
"openAction": { "id": "chapter-1", "fit": "fitBH" }
}
},
"content": [
{ "h1": "Operator's manual" },
{ "break": "page" },
{ "h2": "1. Installation", "id": "chapter-1" },
{ "p": "Unpack the unit and check the contents against the list." }
]
}
}

In a DOCX​

KeyIn the DOCX
ida Word bookmark of the same name
[goto]a hyperlink to that bookmark
[link], svg linka hyperlink
viewerPreferences, openActionno equivalent: a document opens as Word opens it. A WARNING names each setting that differs from its default