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 used | What it does |
|---|---|
[goto, id]text[/goto] | jumps to the block, forward or back across pages |
$global.PAGEREF.id | prints 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=id | every id is a named destination: a viewer opens the file at the block when the name follows its address |
viewerPreferences.openAction.id | the document opens at the block |
| In a DOCX | every 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.
Links
| Link | Takes | Where |
|---|---|---|
[goto, id]…[/goto] | a block's id | any text: p, headings, list items, table cells |
[link, url]…[/link] | an absolute http, https or mailto URL | any text |
link on an svg shape | the same URLs | rect, 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.
| Key | Takes | Default | What it does |
|---|---|---|---|
pageLayout | singlePage, oneColumn, twoColumnLeft, twoColumnRight, twoPageLeft, twoPageRight | singlePage | one 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) |
pageMode | useNone, useOutlines, useThumbs, fullScreen, useAttachments | the outline panel when the document has bookmarks, else none | the panel open when the document opens; fullScreen asks for full-screen mode |
nonFullScreenPageMode | useNone, useOutlines, useThumbs | useNone | the panel shown on leaving full screen; read only when pageMode is fullScreen |
hideToolbar | boolean | false | hides the viewer's toolbars |
hideMenubar | boolean | false | hides its menu bar |
hideWindowUI | boolean | false | hides scroll bars and navigation controls, leaving only the pages |
fitWindow | boolean | false | sizes the window to the first page |
centerWindow | boolean | false | centres the window on the screen |
displayDocTitle | boolean | true when the document has a title | the title bar shows the title rather than the file name |
printScaling | none, appDefault | appDefault | none prints at exact size, which labels, forms and barcodes need |
duplex | simplex, duplexFlipShortEdge, duplexFlipLongEdge | — | one-sided, or two-sided flipped on the short or the long edge |
pickTrayByPDFSize | boolean | — | the print dialogue picks the paper tray by the page size |
printPageRange | pairs of first and last page, from 1 | — | the pages the print dialogue offers: [1, 2, 5, 5] is pages 1-2 and 5 |
numCopies | integer, 1 or more | — | the copies the print dialogue offers |
enforce | ["printScaling"] | — | settings the reader may not change in the print dialogue |
openAction | a destination (below) | the top of page 1, at the viewer's zoom | the view the document opens on |
The rules that hold them together:
enforceneedsprintScalingset, and set tonone: a definition that enforcesappDefault, or leavesprintScalingout, is refused. It is a PDF 2.0 entry: on a 1.7 file it is left out and reported, so pinmetadata.pdfVersion: "2.0"(or claima-4orua-2, which do).displayDocTitle: falseis refused under aua-1,ua-2or 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, oruseAttachmentswith 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 withwritingMode: verticalRl) tells the viewer its pages advance right to left by itself; withpageLayout: "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.
| Key | Takes | What it does |
|---|---|---|
page | integer from 1 | the page to open on. One past the last opens the last, reported. Absent, page 1 |
id | a block's id | opens 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 |
fit | xyz, fit, fitH, fitV, fitR, fitB, fitBH, fitBV (default xyz) | the view (below) |
left | points | the page's left edge in the window |
top | points | the height on the page at the window's top |
bottom, right | points | under fitR, the rectangle's bottom and right |
zoom | number, 1 is 100% | under xyz; absent or 0, the viewer's current zoom |
fit | The window shows | Reads |
|---|---|---|
xyz | a position at a zoom | left, top, zoom; an unset top is the page's top, or the block's |
fit | the whole page | nothing |
fitH | the page's full width | top |
fitV | the page's full height | left |
fitR | a rectangle | left, bottom, right and top, all four required; with one missing the whole page is shown, reported |
fitB, fitBH, fitBV | as fit, fitH, fitV, over the bounds of what is drawn rather than the page | as 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
| Key | In the DOCX |
|---|---|
id | a Word bookmark of the same name |
[goto] | a hyperlink to that bookmark |
[link], svg link | a hyperlink |
viewerPreferences, openAction | no equivalent: a document opens as Word opens it. A WARNING names each setting that differs from its default |