This package requires MkDocs version 1.0 or higher (0.17 works as well)
Python 3.6 or higher
WeasyPrint depends on cairo, Pango and GDK-PixBuf which need to be installed separately. Please follow the installation instructions for your platform carefully:
Set the value to false if you don't need a cover page. default: true
back_cover
Set the value to true if you need a back cover page. default: false since: v0.8.0
You would be better to install the qrcode package:
pip install qrcode
cover_title
Set the title text in cover page. default: use site_name in your project mkdocs.yml
cover_subtitle
Set the subtitle text in cover page. default: None
cover_logo
Set the logo image in cover page. This value is URL or simply specify the relative path to the docs directory. default: None since: v0.8.0
for Heading and TOC
toc_title
Set the title text of Table of Content. default: Table of Content since: v0.4.0
heading_shift
Set this value to false, disable shift heading in child page. default: true
In this flags enable, heading move down one level in child page.
toc_level
Set the level of Table of Content. This value is enabled in the range of from 1 to 3. default: 3
ordered_chapter_level
Set the level of heading number addition. This value is enabled in the range of from 1 to 3. default: 3
excludes_children
Set the page id of nav url. If the id matches in this list, it will be excluded from the heading number addition and table of contents. default: []
for Page
exclude_pages
Set the page id of nav url. If the id matches in this list, it will be excluded page contents. default: [] since: v0.3.0
convert_iframe
List of iframe to a conversions. Every iframe that matches a src in this list will be replace to a contains each img and/or text. it's using for such as embedded VIDEO. default: [] since: v0.6.0
This option allows you to use a different destination for the PDF file. default: pdf/document.pdf
custom_template_path
The path where your custom cover.html and/or styles.scss are located.
default: templates since: v0.8.0
enabled_if_env
Setting this option will enable the build only if there is an environment variable set to 1. This is useful to disable building the PDF files during development, since it can take a long time to export all files. default: None
PDF generation can take significantly longer than HTML generation which can slow down mkdocs's built-in dev-server.
Adding enabled_if_env: ENABLE_PDF_EXPORT under - with-pdf: disables PDF generation during development. Run the dev-server normally:
$ mkdocs serve
INFO - Browser Connected: http://127.0.0.1:8000/
INFO - Running task: builder (delay: None)
INFO - Building documentation...
WARNING - without generate PDF(set environment variable ENABLE_PDF_EXPORT to 1 to enable)
... 2 seconds later ...
INFO - Reload 1 waiters: /.../index.md
and to build files to deploy specify ENABLE_PDF_EXPORT=1 at the command line:
$ ENABLE_PDF_EXPORT=1 mkdocs build
...
INFO - Converting 10 articles to PDF took 7.1s
INFO - Documentation built in 8.29 seconds
debug_html
Setting this to true will out HTML to stdout on build time. default: false
Note: WeasyPrint and Google Chrome are not fully compatible.
show_anchors
Setting this to true will list out of anchor points provided during the build as info message. default: false since: v0.7.4
verbose
Setting this to true will show all WeasyPrint debug messages during the build. default: false
Custom cover page and document style
It is possible to create a custom cover page for the document.
You can also add a custom style sheet to modify the whole document.
To do so, add a templates folder at the root level of your mkdocs project and place a cover.html and/or a styles.scss inside.
Alternatively, you can specify a different location with the custom_template_path option.
Custom cover page
Using jinja2 syntax, you can access all data from your mkdocs.yml.
To make template creation easier, you can use plugin_some_plugin to access variables from plugins.
E.g. use {{ author }} to get the author from your mkdocs.yml that looks like:
plugins:
- with-pdf:
author: WHO
You can use custom variables extra: in your mkdocs.yml
And, you can check it in the log if run with verbose or debug_html options.
Custom stylesheet
Since your stylesheet is appended to the default ones, you can override every setting from them.
Tip: setting the debug_html option to true to get the generated html that is passed to weasyprint can help you determine the html tags, classes or identifiers you want to modify in your stylesheet.
Advanced Rendering Hooks (Experimental)
You can hook the PDF rendering process by creating a pdf_event_hook.py(or pdf_event_hook/__init__.py) in your working directory (usually the same directory as mkdocs.yml). since: v0.8.2
$ mkdocs build
INFO - Found PDF rendering event hook module.
INFO - Cleaning site directory
INFO - Building documentation to directory: /tmp/sample/site
INFO - (hook on inject_link: Home)
...
Contributing
From reporting a bug to submitting a pull request: every contribution is appreciated and welcome. Report bugs, ask questions and request features using Github issues.
If you want to contribute to the code of this project, please read the Contribution Guidelines.