Skip to content

Generating PDF documents

PDF documents are generated by default once the plugin is registered. The enabled option can be used as a toggle, for instance with an environment variable:

plugins:
  - exporter:
      formats:
        pdf:
          enabled: !ENV [MKDOCS_EXPORTER_PDF, true]

Each page gets a PDF document next to its HTML file (e.g. guide/intro/index.pdf for guide/intro/index.html).

This page covers which pages get a document and what documents contain; the next pages of this guide cover cover pages, headers and footers, tables of contents, books, styles and scripts and buttons. See Performance for concurrency and the cache.

Choosing pages

By default, every page gets a PDF document. A page can opt out with its front matter:

---
exporter:
  pdf:
    enabled: false
---

In explicit mode, pages have to opt in instead:

plugins:
  - exporter:
      formats:
        pdf:
          explicit: true
---
exporter:
  pdf:
    enabled: true
---

While serving

To keep mkdocs serve responsive, documents are not generated while serving. Enable the serve option to generate them anyway:

plugins:
  - exporter:
      formats:
        pdf:
          serve: true

The browser is then kept open from one rebuild to the next.

Links to other pages of your website are resolved to absolute URLs, based on site_url. Use the url option to point them somewhere else (e.g. where your website is published, when site_url is not set):

plugins:
  - exporter:
      formats:
        pdf:
          url: https://docs.example.com/

When there is no URL at all, links are relative to the PDF document, which works when documents are published alongside the website. Links to anchors of the same page, and links to other websites, are left untouched.

Document information

Documents are given the page's title, an author, a subject and keywords, shown by PDF readers and used by search engines:

Information Taken from
Title The page's title
Author The page's author metadata, or site_author
Subject The page's description metadata, or site_description
Keywords The page's keywords or tags metadata
---
author: Jane Doe
description: How to configure the plugin.
tags:
  - configuration
---

Page titles

Some themes don't print the page's title when its content has no first-level heading. The title option inserts it in documents:

plugins:
  - exporter:
      formats:
        pdf:
          title: true

Accessibility

Documents are tagged: their structure is described, so that screen readers can read them. They have bookmarks following their headings, and their language is the website's (<html lang>). Books are tagged too, which can be disabled.

Browser

The browser can be configured too:

plugins:
  - exporter:
      formats:
        pdf:
          browser:
            timeout: 60000 # Time given to each document to render (ms)
            channel: chrome # Use an installed browser instead of Chromium (138 or later)
            debug: true # Log the browser's console
            args: [] # Extra command-line arguments