Skip to content

Customize the PDF layout↵

The print page is a regular HTML page, so you control the printed layout with CSS. Add your own stylesheet with extra_css. It loads after the plugin's CSS, so your rules take precedence.

plugins:
    - print-site

extra_css:
    - css/print.css
@page {
    @bottom-right { content: counter(page) " / " counter(pages); }
}

Tip

Untick Headers and footers in the print dialog of your browser. Otherwise the browser adds its own date, title and URL in the page margins.

Page numbers↵

The plugin puts Page 1, Page 2, etc. in the bottom right corner of each page. Override the @bottom-right page margin box to change the format:

@page {
    /* "3" */
    @bottom-right { content: counter(page); }
}
@page {
    /* "3 / 12" */
    @bottom-right { content: counter(page) " / " counter(pages); }
}

To remove the page numbers, use content: none. To move them, set content: none on @bottom-right and use another margin box, such as @bottom-center or @top-right. Margin boxes can also show fixed text, for example a document title or a version number:

@page {
    @top-left { content: "My project documentation v1.2"; }
}

Page numbers in the table of contents↵

Browsers cannot show page numbers in the table of contents of the print page. That needs the CSS function target-counter(), which Chrome, Firefox and Safari do not support. Instead, create the PDF with bookmarks, a clickable table of contents in the sidebar of the PDF viewer.

If you need printed page numbers in the table of contents, use a tool that supports target-counter(), such as Paged.js or WeasyPrint, or a PDF plugin such as mkdocs-exporter.

Page size and margins↵

The default page size is A4 portrait. Change it with size and margin:

@page {
    size: letter landscape;
    margin: 20mm 15mm;
}

Page breaks↵

Each page of your site, and each section, starts on a new page in the PDF. To force a page break inside a page, use the .print-site-plugin-page-break class:

Content on the first page.

<div class="print-site-plugin-page-break"></div>

Content on the next page.

With the Attribute Lists extension enabled, you can add a page break after an element:

This paragraph ends a page.
{ .print-site-plugin-page-break }

To keep an element on one page, use break-inside: avoid in your CSS. The plugin already does this for paragraphs, code blocks, quotes, figures and content tabs.

Note

The @page rules apply when you print any page of your site, not only the print page. Chrome and Edge support page margin boxes. Firefox does not (see avoid creating PDFs with Firefox). See export to PDF for how to automate PDF creation with Chrome.