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

mdbook-pdf fails to render on headless Ubuntu machine #50

Closed jb2cool closed 2 months ago

jb2cool commented 2 months ago

I have an Ubuntu 20.04 server and I've installed mdbook and mdbook-pdf via cargo, i also think i needed a browser to be able to export to PDF so i installed chromium-browser via apt. This should pretty much be as simple and clean a build as can be done.

book.toml reads:

ubuntu@core-018:~/2024_scebook$ cat book.toml
[book]
title = "Scientific Computing Environment"

[output.html]

[output.pdf]

When i try to build the book i get:

ubuntu@core-018:~/2024_scebook$ mdbook build ~/2024_scebook --dest-dir /var/www/html
2024-08-16 09:02:09 [INFO] (mdbook::book): Book building has started
2024-08-16 09:02:09 [INFO] (mdbook::book): Running the html backend
2024-08-16 09:02:09 [INFO] (mdbook::book): Running the pdf backend
2024-08-16 09:02:09 [INFO] (mdbook::renderer): Invoking the "pdf" renderer
Generating PDF, please be patient...
Error: Navigate failed: net::ERR_FILE_NOT_FOUND
2024-08-16 09:02:11 [ERROR] (mdbook::renderer): Renderer exited with non-zero return code.
2024-08-16 09:02:11 [ERROR] (mdbook::utils): Error: Rendering failed
2024-08-16 09:02:11 [ERROR] (mdbook::utils):    Caused By: The "pdf" renderer failed

Full trace (i think) attached. trace.log

jb2cool commented 2 months ago

My book isn't large, 68 pages i think, just markdown text and some embedded images.

HollowMan6 commented 2 months ago

hmm,I'm not sure why it goes to this path in your case:

1723798486857

https://github.com/HollowMan6/mdbook-pdf/blob/main/src/main.rs#L49C10-L49C21

The destination is controlled by mdBook. We just receive that configuration and calculate the path here. Or maybe there's something wrong/exceptional with your system configuration. You might want to try the container https://github.com/HollowMan6/mdbook-pdf/tree/main?tab=readme-ov-file#run-with-docker and see how it goes. if it continues and you have the book open-sourced somewhere, I can try it out.

jb2cool commented 2 months ago

I've changed by build command from mdbook build ~/2024_scebook --dest-dir /var/www/html to mdbook build ~/2024_scebook --dest-dir /var/www (to hopefully remove the double-html) and now my error has changed, it's now saying:

ubuntu@core-018:~$ mdbook build ~/2024_scebook --dest-dir /var/www
2024-08-16 11:40:14 [INFO] (mdbook::book): Book building has started
2024-08-16 11:40:14 [INFO] (mdbook::book): Running the html backend
2024-08-16 11:40:14 [INFO] (mdbook::book): Running the pdf backend
2024-08-16 11:40:14 [INFO] (mdbook::renderer): Invoking the "pdf" renderer
2024-08-16 11:40:14 [ERROR] (mdbook::renderer): The command `mdbook-pdf` wasn't found, is the "pdf" backend installed? If you want to ignore this error when the "pdf" backend is not installed, set `optional = true` in the `[output.pdf]` section of the book.toml configuration file.
2024-08-16 11:40:14 [ERROR] (mdbook::utils): Error: Rendering failed
2024-08-16 11:40:14 [ERROR] (mdbook::utils):    Caused By: Unable to start the backend
2024-08-16 11:40:14 [ERROR] (mdbook::utils):    Caused By: No such file or directory (os error 2)

But mdbook-pdf is clearly installed, i even stripped out all Rust and installed that afresh.

HollowMan6 commented 2 months ago

But mdbook-pdf is clearly installed, i even stripped out all Rust and installed that afresh.

mdbook-pdf should be called by mdbook directly; if mdbook can't find mdbook-pdf, I'm then not clear what might go wrong, and it's out of mdbook-pdf's control, but it worked before, right? I don't think it goes wrong just because you changed the parameter of --dest-dir

About --dest-dir, I didn't realize that we could specify this parameter previously, let me see if this causes any bugs, and I'll implement fixes when needed.

HollowMan6 commented 2 months ago

I checked, and it works well still with --dest-dir

Some checklist for you:

jb2cool commented 2 months ago

Building the book for hosting is just fine this is a new thing for us to want to wrap that up as a PDF to make it more portable. Just seems weird to me that if the destination directory is one thing i get one error (where mdbook seemingly CAN find mdbook-pdf and if i set the destination directory to one level higher i get a different error about mdbook-pdf not being found.

jb2cool commented 2 months ago

Yes, ubuntu user has write access to /var/www, hosting the html files there works just fine.

Don't think i ever did a sudo for anything mdbook.

ubuntu@core-018:~$ which mdbook-pdf
/home/ubuntu/.cargo/bin/mdbook-pdf
ubuntu@core-018:~$ which mdbook
/home/ubuntu/.cargo/bin/mdbook
HollowMan6 commented 2 months ago

Hmm, if so, that's weird. I would say it should be an environment issue for that mdbook-pdf not found one, but it's not quite clear to me why it happens. For the ERR_FILE_NOT_FOUND one, maybe Chromium has some issue accessing /var/www/html directly. if you just want to get the pdf, and not put it under /var/www/pdf/output.pdf, then just let this fail and go to your current directly and build your book again with mdbook build:

cd ~/2024_scebook
mdbook build
jb2cool commented 2 months ago

now i feel like an idiot, why did i not think of that.

Yes, i can absolutely build the book for hosting and the PDF for portable distribution separately, thanks.