An mdBook backend renderer to generate a single PDF file for a full book.
There are other similar projects, but most rely on chrome in some way to generate a PDF. This project only optionally
requires Node.js to be installed for code block syntax highlighting. If you don't want highlighting or don't have Node.js installed, you can specify you don't want highlighting in the config settings with highlight = false
.
To use this backend, you'll need to add the following to your book.toml
file:
toml
[output.compress]
and install this project
bash
cargo install mdbook-compress
If you want to keep the default HTML output, you'll also need to add in
[output.html]
if it's not already there
The resulting PDF will end up in /book/compress/<book-title>.pdf
. If you want to have a look at an example PDF, you can have a look at this one which is the whole reaoson this project exists in the first place.
There are a few config options. They're all below and have a few comments to explain things. All the values are the default values.
```toml [output.compress]
subtitle = ""
fontsize.title = 12 fontsize.h1 = 11 font_size.h2 = 10
fontsize.h3 = 8 fontsize.h4 = 7 fontsize.h5 = 6 fontsize.h6 = 6 font_size.text = 5
page.size = "A4" page.landscape = false
page.spacing.line = 1.5 page.spacing.margin = [20.0, 20.0]
highlight = true ```
If you need a custom page size, you can give the width and height (x
and y
) dimensions in millimeters like this
toml
page.size = { x = "width", y = "height" }
Because there's no way (that I know of) to call JS scripts quickly other that running a node command, building the PDF can take a bit of time.
If you know a faster way to do this, please open an issue or a PR.
If you want to know what different dependencies are used for, here you go. The descriptions are all a bit general, because anything more specific would make the table too big.
| Dependency | Version | Use |
|-------------------------------------------------------------------|---------|----------------------------------------------------|
| serde
| 1.0.152 | Config struct deserialisation |
| mdbook
| 0.4.25 | Getting mdbook config and some error printing |
| genpdf
| 0.2.0 | PDF building (really nice library btw) |
| anyhow
| 1.0.68 | Error handling |
| scraper
| 0.14.0 | Parsing HTML output from highlight.js |
| ego-tree
| 0.6.2 | Required for function call types when highlighting |
| pulldown-cmark
| 0.9.2 | Markdown parsing |