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

embedded images not visible in PDF #6

Closed danieleades closed 1 year ago

danieleades commented 1 year ago

i have a document with embedded images. The embedded images are not visible when built as a PDF. Should i expect this to work?

Images are in PNG format

reproduction: https://github.com/danieleades/mdbook-d2/tree/file-extension/example

HollowMan6 commented 1 year ago

Hi! I've checked the book you mentioned, and it looks like there's some issue with your code:

https://github.com/danieleades/mdbook-d2/blob/96ab66603899209f044b1d47e47af6dbac408d2c/src/backend.rs#L124

Screenshot from 2023-01-10 21-43-11

The image src path is wrong, so actually the generated web page can't even show the picture, not to mention the pdf one.

After I changed that line into let depth = ctx.path.ancestors().count() - 2;, the embedded images will display normally when built as a PDF.

output.pdf

So this is not something related to mdbook-pdf, and I'm sure images will be OK as long as they display normally in web pages.

danieleades commented 1 year ago

now this is where it gets weird. I've been developing using mdbook serve rather than mdbook build. If i use serve then the image displays correctly in the html... Not clear to me why that would be the case.

Regardless- the fix you proposed works perfectly. thank you

HollowMan6 commented 1 year ago

now this is where it gets weird. I've been developing using mdbook serve rather than mdbook build. If i use serve then the image displays correctly in the html... Not clear to me why that would be the case.

Regardless- the fix you proposed works perfectly. thank you

Finally I understand why you didn't find this bug, as basically .. works just like . without any error shown when you are already in the root path.

If you use mdbook serve, as it will serve as a local server in a root path, ../d2/1.1.png will be equivalent to ./d2/1.1.png. While it's not the case when you open print.html directly.