HollowMan6 / mdbook-pdf

A backend for mdBook written in Rust for generating PDF based on headless chrome and Chrome DevTools Protocol. (用 Rust 编写的 mdBook 后端,基于headless chrome和Chrome开发工具协议生成PDF)
https://crates.io/crates/mdbook-pdf
GNU General Public License v3.0
153 stars 18 forks source link

Can't be used on M2 Pro chip? #30

Closed syang closed 11 months ago

syang commented 11 months ago

Hi @HollowMan6 ,

I am trying to export a book into PDF format and found mdbook-pdf.

  1. First, I cloned the project into ~/personal/mdbook-pdf

  2. I compiled the source, I found the binary is in /Users/syang/personal/mdbook-pdf/target/debug/mdbook-pdf

  3. I add the path into the PATH variable, export PATH="/Users/syang/personal/mdbook-pdf/target/debug:$PATH"

  4. Now I start serving, and I got the following error message

➜ mdbook git:(main) ✗ mdbook serve
2023-11-18 08:12:05 [INFO] (mdbook::book): Book building has started 2023-11-18 08:12:05 [INFO] (mdbook::book): Running the pdf backend 2023-11-18 08:12:05 [INFO] (mdbook::renderer): Invoking the "pdf" renderer thread 'main' panicked at 'called Result::unwrap() on an Err value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:63:10 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace 2023-11-18 08:12:05 [ERROR] (mdbook::renderer): Renderer exited with non-zero return code. 2023-11-18 08:12:05 [ERROR] (mdbook::utils): Error: Rendering failed 2023-11-18 08:12:05 [ERROR] (mdbook::utils): Caused By: The "pdf" renderer failed

Note: if I took out the output.pdf instruction from the foo.book configuration file, then I can successfully create the book site.

Can you give some suggestion about how I can solve the problem? (I am using M2 Pro chip and Ventura 13.5 MacBook)

Thanks

HollowMan6 commented 11 months ago

The error indicates that print.html can't be found: https://github.com/HollowMan6/mdbook-pdf/blob/39bb46f497800c3231b0011996bbc8b6f90f0ee5/src/main.rs#L59-L63

Looking at your log, I can see that the html backend didn't get called before pdf renderer, a working one should look like this:

$ mdbook build
2023-11-18 17:33:47 [INFO] (mdbook::book): Book building has started
2023-11-18 17:33:47 [INFO] (mdbook::book): Running the html backend
2023-11-18 17:33:47 [INFO] (mdbook::book): Running the pdf backend
2023-11-18 17:33:47 [INFO] (mdbook::renderer): Invoking the "pdf" renderer
Generating PDF, please be patient...
PDF successfully generated at: ...

So I guess you may forgot to put [output.html] before [output.pdf], or you set [output.html.print] as disabled, and I have mentioned those things already in the README. Do remember to read through README before you continue: https://github.com/HollowMan6/mdbook-pdf?tab=readme-ov-file#installation--usage

HollowMan6 commented 11 months ago

Just remove the theme parameter here to use the default theme: https://github.com/HollowMan6/mdbook-pdf/blob/main/test_doc/book.toml#L24 Or replace it with any theme you want according to mdbook configuration Screenshot from 2023-11-18 18-48-48

syang commented 11 months ago

Thanks for the pointer. Two more questions about the output format (I am fine-tuning the output format now, thanks for the help making me here)

  1. How to control the font-size?
  2. How to control the font-style?
  3. How to control the font-color (right now characters in my PDF book seem to be pretty like colored, not total deep black).

Thanks, definitely a great project for people who wanted to produce paper document!

My current configuration

landscape = false display-header-footer = true print-background = false # theme = "ayu" scale = 0.7 paper-width = 8 paper-height = 10 margin-top = 0.5 margin-bottom = 0.5 margin-left = 0.5 margin-right = 0.5 page-ranges = "" ignore-invalid-page-ranges = false prefer-css-page-size = true

HollowMan6 commented 11 months ago

All of your questions now relate to mdbook and is not directly controllable by mdbook-pdf. mdbook-pdf generates PDF via print.html, so you can of course customize those things via css/print.css for printer output. https://rust-lang.github.io/mdBook/format/theme/index.html