You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An MkDocs plugin to export content pages as PDF files
The pdf-export plugin will export all markdown pages in your MkDocs repository as PDF files using WeasyPrint. The exported documents support many advanced features missing in most other PDF exports, such as a PDF Index and support for CSS paged media module.
Requirements
This package requires MkDocs version 1.0 or higher (0.17 works as well)
Python 3.4 3.5 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:
Explicit support for your mkdocs theme is probably required. As of now, the only supported theme is mkdocs-material. A generic version will just generate the PDF files and put the download link into a <link> tag.
Note: If you have no plugins entry in your config file yet, you'll likely also want to add the search plugin. MkDocs enables it by default if there is no plugins entry set, but now you have to enable it explicitly.
Setting this to true will show all WeasyPrint debug messages during the build. Default is false.
media_type
This option allows you to use a different CSS media type (or a custom one like pdf-export) for the PDF export. Default is print.
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 is not set.
combined
Setting this to true will combine all pages into a single PDF file. All download links will point to this file. Default is false.
combined_output_path
This option allows you to use a different destination for the combined PDF file. Has no effect when combined is set to false. Default is pdf/combined.pdf.
theme_handler_path
This option allows you to specify a custom theme handler module. This path must be relative to your project root (See example below). Default is not set.
For this to take effect, use the extra_css directive in mkdocs.yml, as described in the MkDocs user guide.
Adding support for new themes
If you use a mkdocs theme which is currently not supported, check out the themes/material.py file and adjust it according to your requirements. You will have to implement two methods to support a theme:
get_stylesheet should return a CSS which gets applied to fix issues with weasyprint
modify_html should add a link to the PDF download before writing it to disk
If there is no explicit support for your theme, the generic version will just add a <link> tag in the head pointing to the generated PDF.
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.
Special thanks
Special thanks go to Stephan Hauser for the original development of this plugin.