Documentation ends up on paper more often than you might expect: a runbook
taken into a server room with no network, a chapter handed out at a training,
a PDF attached to a change request. Any single page already prints cleanly
with the browser’s Cmd/Ctrl+P: the navbar, sidebar, outline and buttons
carry Bootstrap’s d-print-none class and stay off the paper, so the theme
needs no “print this page” button. For a whole section or book, turn on the
print output format. Every section then gets a print view that joins its
pages, in sidebar order, into one document with a table of contents, ready to
print or save as a PDF.
Enabling whole-section print
The theme defines the print output format but leaves it to the site, because
it adds a page per section to every build. Add it to section in your
hugo.yml:
Each key under outputs replaces the list for that page kind rather than
adding to it, so keep every format the kind already had (here HTML, RSS
and markdown); a format you leave out is no longer generated.
Each section’s print view lives under _print, which comes right after the
language prefix:
| Page | Print view |
|---|---|
/docs/customize/ |
/_print/docs/customize/ |
/docs/ |
/_print/docs/ |
/blog/release/ |
/_print/blog/release/ |
Readers reach it through Print entire section in the page action menu, or
by searching the command palette for the same action (print_section). It
prints the section the page belongs to: from /docs/customize/print/ it
prints the whole Customization section, not just this page.
The structure of a print view
A print view contains, from top to bottom:
- A notice: “This is the multi-page printable view of this section. Click here to print. Return to the regular view of this page.” It appears on screen only, never on paper.
- The section title and summary.
- A table of contents for the whole section, numbered
1:,2:,2.1:by level and linked to anchors in the document. - Every page in turn, titled “number - title” (for example “1 - Configuration”), with its description as a standfirst and its body unchanged.
Pages follow the sidebar order (weight), with subsections expanded in place.
Every page after the first starts on a new sheet. The first page does so only
when the section index’s own body is longer than 50 words, so that an index of
one sentence does not waste a sheet. To change the threshold:
To leave out the table of contents for the whole site:
or for one section, in its index’s front matter:
Excluding pages
Some pages add nothing on paper: a page of links, a redirect note, a single
large screenshot. Set no_print to leave one out:
no_print affects only the section print view; the page itself still prints
with Cmd/Ctrl+P. Sidebar dividers (sidebar_divider) are left out
automatically, but when a divider is a section, its child pages stay in the
print sequence.
How components look in print
On paper, nothing can be clicked or expanded, so the same rule applies to the section print view and to a single page printed from the browser: interactive components become static, and collapsed content is printed open.
| Component | Print shape |
|---|---|
| Callouts | Static blocks. All collapsible kinds (- / + / DETAILS) expand. Borders turn gray and backgrounds are removed |
| Tabs | The tab bar disappears and every panel is printed in turn, each under its own heading |
| Code Blocks | Copy and fold controls removed, maximum height and scrolling dropped, long lines wrapped |
| Tables | Complete static tables. On screen the print view keeps keyboard scrolling; on paper the table expands and its header repeats on every page |
| Images | Image and caption kept, zoom removed, width limited to the text column |
| Gallery | The grid becomes a vertical stack |
| FileTree | A static panel with every directory expanded. A split layout keeps its build-time width |
| Fields | The complete definition list, the same as on screen |
| Math | Statically rendered KaTeX / MathML |
| Mermaid | The print view keeps the source and loads no engine. A browser-printed page shows the rendered diagram, or the source if it has not rendered |
| Markmap | The print view keeps the outline source and loads no runtime. A browser-printed page shows the rendered map without its floating notes, or the source if it has not mounted |
| PlantUML | The print view keeps the source and loads no runtime. A browser-printed page shows the rendered image, or the source if it has not rendered |
| ECharts · Infographic | The print view keeps the fenced source and draws no chart. A browser-printed page shows the rendered chart, or the declared options / DSL if it has not mounted |
| Asciinema · OpenAPI | A labeled static link to the recording or specification; none of the three runtimes loads |
| Timeline · Updates | Static axis or heading + metadata line on the light paper palette; avoids page breaks inside entries |
| Video · Audio | Static figure with poster (for video), caption and visible file or watch URL; no <video>, <audio> or <iframe> in the print view |
| Social | Static quoted card with author, body, attachments and original-post link on the paper palette |
| Maps | Numbered place list with coordinates and links; no Leaflet map canvas |
| Cards / steps / badges / keys | Static, with content unchanged |
Besides the shell, print leaves out the page action menu, the feedback widget, heading anchor links and inline copy buttons. Before printing a page with diagrams from the browser, wait until they have finished drawing.
Browser print styles
A set of @media print rules, shared by single pages and section print views,
lays the page out for paper:
A4paper with18mm 16mm 20mmmargins, 10.5pt body text, and the light palette even when the reader browses in dark mode.- Text uses the
--td-print-font-familytypography token; see Brand and appearance. - Headings stay with the text that follows them (
break-after: avoid-page), and paragraphs and list items keep at least three lines together at a page break. - Tables, images, blockquotes, callouts, cards and tabs avoid breaking across pages where they can. Code blocks may break, and long lines wrap rather than being cut off.
- A closed
<details>always prints open, so collapsed callouts and file tree directories show their content. - Links are dark blue and underlined, without the URL printed after them. If your readers need the addresses on paper, add them:
Put any other print styling in a @media print block in
assets/css/project.css; no template change is needed.
Copying into rich-text editors
Readers also copy articles into WeChat, Word or an email. When they copy part of an article and paste it into a rich-text editor, they get typeset text in the same light palette print uses, without the page background, dark-mode colors, heading anchors, copy buttons or line numbers. Selecting the whole page (⌘/Ctrl+A) copies only the article: title, description and body.
- Headings, lists, quotes, callouts, tables and code blocks keep their structure, with sizes in pixels, so editors that drop stylesheets still show them correctly.
- Code blocks keep their syntax colors. Copied in dark mode, a code block stays a dark card while the prose around it is dark text on white.
- A few words selected inside one paragraph copy without formatting and take the style of the document they are pasted into.
- Pasting as plain text is unchanged.
To restyle the pasted result, override the print palette, for example
--td-print-ink or --td-print-quote-line, in assets/css/project.css. To
keep the browser’s own copy behavior, set rich_copy: false for the site, or
in a page’s front matter for that page:
Each editor filters pasted HTML in its own way, so check an important article in the editor you publish to.
Replacing the print templates
To change the structure, for example to add a running header or a different
numbering, override the narrowest partial under layouts/_partials/print/:
The last three can also be overridden for one content type: a file such as
print/page-heading-blog.html or print/content-book.html takes precedence
over the generic partial for pages of that type.
A whole book (type: book) prints through its own path, which keeps chapter
numbers, figure numbers and cross-references continuous across the book; see
Books.
Verify
From your site’s root, build and check that a section where you enabled
print has its print view. Replace the example path with that section’s
output, including its language prefix if it has one:
Then open Print entire section on the running site:
- The print view contains the section’s pages, without those marked
no_print: true. Cmd/Ctrl+Pshows no notice, navbar or buttons in the preview.- On a page with tabs and a collapsed callout, every panel is open in the preview.
- In a saved PDF, the page breaks fall where you want them; if not, adjust
section_break_wordcount.
Related
- Books — numbering, indexes and print for a whole book
- Organizing content — print order is sidebar order
- Brand and appearance — the print font token
- AI-agent support — the other non-HTML output
- Configuration — full definitions of
outputsandparams.print.*