Skip to main content

mdbook-pdf

last-commit release-date Crate mdbook-pdf build mdbook-pdf test Python package

Followers watchers stars forks

Open Source Love GPL Licence Repo-Size

中文

Blog

A backend for mdBook written in Rust for generating PDF based on headless chrome and Chrome DevTools Protocol.

Installation & Usage

Since it's a plugin (backend) for mdBook, first of all you should ensure that mdbook is available.

If your machine's architecture is x86_64, or you are using Linux for ARM64, check the successful build GitHub Actions workflows/release, click into the latest one, and then you can get a binary from the Artifacts (including Windows, Linux, macOS).

Otherwise, make sure the rust compiling environment is available, execute cargo install mdbook-pdf to compile and install.

If you want to compile the latest version, make sure the Rust build environment is available (cargo build). Run cargo install --git https://github.com/HollowMan6/mdbook-pdf.git, or alternatively, you can clone the repository and compile it yourself. (Run git clone https://github.com/HollowMan6/mdbook-pdf.git, in the cloned folder, run cargo build --release , get the executable in target/release/, and put it in PATH)

For running, please have Google Chrome / Chromium / Microsoft Edge already available (installed at the default location, in PATH or binary location configured). If not, and mdbook-pdf has the fetch feature enabled (It is not enabled by default, you need to use cargo install mdbook-pdf --features fetch to recompile for enabling), the program will try to automatically download the Chromium browser and run it (Note: if you are on Linux, there may be problems if chromium dependencies are not satisfied / using non-x86_64 architectures).

  • On Windows 10 and above, the program can generate PDF normally without installing any additional software, because Microsoft Edge is the browser provided with Windows system. Of course, considering the support for the older versions of Windows without Edge, you can install Google Chrome on your computer.
  • In MacOS, you need to install Google Chrome / Microsoft Edge or Chromium.
  • In Linux, you can choose to install any of the Google Chrome / Chromium / Microsoft Edge browsers. It is recommended to install Chromium. The name of this software package in your Linux distribution is commonly chromium or chromium-browser (Note: for Ubuntu later than 18.04, you have to install chromium-browser through snap).

Make sure the following exists in your book.toml:

[output.html]

[output.pdf]

And also [output.html.print] is not disabled (it should be enabled by default, so don't worry if the following lines doesn't occur in you book.toml).

[output.html.print]
enable = true

A simplest book.toml is as follows:

[book]
title = "An Example"

[output.html]

[output.pdf]

Finally you can build your book and get the PDF file with mdbook build command, your PDF file will be available at book/pdf/output.pdf.

Run with Docker

You can also use this docker image.

docker run --rm -v /path/to/book:/book hollowman6/mdbook-pdf

If your book have other Rust dependencies, you can install them on your local machine (if using Linux), or if you are not using Linux, download the Linux executables of corresponding architecture to a dir, replace ~/.cargo/bin with your path.

docker run --rm -v /path/to/book:/book -v ~/.cargo/bin:/mdbook hollowman6/mdbook-pdf

Configuration

Support customize PDF paper orientation, scale of the webpage rendering, paper width and height, page margins, generated PDF page ranges, whether to display header and footer as well as customize their formats, and more.

Check book.toml and comments for details for the available configurations of [output.pdf].

Common Issues

  1. Support for Firefox in mdbook-pdf!

Currently, although Puppeteer supports something similar to Chrome DevTools Protocol Page.printToPDF according to its documentation, rust-headless-chrome doesn't.

  1. Broken links!

I've already submitted a PR for mdBook to fix this by making print page (print.html) links link to anchors on the print page, but it's not merged yet. You can try my PR fork for this to work.

If you have relative links that link outside the book, please provide the static hosting site URL for it to get fixed.

  1. Can you add the bookmark to the PDF reflecting the Table of Contents, just like what wkhtmltopdf is supported?

This has already been realized by Chromium, in v0.1.11+, you can control it by the generate-document-outline option.

  1. Force page breaks in the markdown source that is respected by mdbook-pdf!

Referring to #9, you can use the following syntax to force page breaks in the markdown source:

<div style="page-break-before:always">&nbsp;</div>
<p></p>
  1. Failed to render my book for PDF in mdbook-pdf!

Will appreciate if you can report it to the issue tracker providing all the traces for mdbook-pdf rendering as well as your book.toml. You can also provide the link to your book's repository if it's open source.

RUST_BACKTRACE=full RUST_LOG=trace mdbook build

Metadata

Release files for mdbook-pdf-outline 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdbook-pdf-outline 0.1.6
File Size Uploaded Provenance Actions
mdbook_pdf_outline-0.1.6.tar.gz 20.4 kB Without provenance Details for mdbook_pdf_outline-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mdbook-pdf-outline 0.1.6
File Interpreter ABI Platform Actions
mdbook_pdf_outline-0.1.6-py3-none-any.whl Python 3 none any Details for mdbook_pdf_outline-0.1.6-py3-none-any.whl

Total release size: 40.8 kB

Release files / mdbook_pdf_outline-0.1.6.tar.gz

Download URL mdbook_pdf_outline-0.1.6.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
18f4c39606297cfb5cabeac90a3c607b17d58988aa1e8559f22424c965cda20c
BLAKE2b-256 checksum
How to use checksums
e70271ec4fb5e19f1e3c8efbbba558bc6db9f370a7f15a64c1f0afea41e261d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / mdbook_pdf_outline-0.1.6-py3-none-any.whl

Download URL mdbook_pdf_outline-0.1.6-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67896ec82c5562071d39042663ee4abe7b953e36fcfba66e92164c6af55b0926
BLAKE2b-256 checksum
How to use checksums
4f1286da71c898012ec126aa93e7aca19681b425c2f0355940b2b829c7d9c3e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for mdbook-pdf-outline 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page