A backend for mdBook written in Rust for generating PDF based on headless chrome and Chrome DevTools Protocol.
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
orchromium-browser
(Note: for Ubuntu later than 18.04, you have to installchromium-browser
throughsnap
).
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
.
You can also use this docker image.