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

The content in built pdf file is messy, how to fix it? #49

Closed onbigion13 closed 3 months ago

onbigion13 commented 3 months ago

I installed mdbook and mdbook-pdf, but after build the md docs, I found that the content in pdf file cannot be read.

HollowMan6 commented 3 months ago

What do you mean? Any details?

onbigion13 commented 3 months ago

Thanks for your replying, here I show the content I build.

1

Indeed, it's content is as below:

image

onbigion13 commented 3 months ago

No matter Chinese or English, the content build are both messy.

HollowMan6 commented 3 months ago

Thank you for letting me know the actual book you are building. I built the book at my side and everything is fine at my side (see attached file and also the config file I appended to book.toml), so I would say it's related to the missing Chinese fonts in your system (you will find similar results if you directly print from Chrome). I have also experienced such an issue in the CI, and this is how I solved this (by installing Chinese fonts such as fonts-wqy-microhei or fonts-wqy-zenhei) https://github.com/HollowMan6/mdbook-pdf/commit/d884679354c937e0aa4f0091024c93004031a893, hope this helps.

output.pdf

[output.pdf]
static_site_url = "https://nomicon.purewhite.io/"

[output.pdf-outline]
onbigion13 commented 3 months ago

Thanks for your relying. I have installed the fonts you mentioned, While the compiled pdf still not display Chinese text. And there are 2 strange things I wanna share.

  1. the compiled pdf file can not display in Adobe Acrobat DC Pro, while can show content in other softwares, like Edge, Chrome, Sumatra. But the content is messy in Acrobat DC.
  2. earlier days, the compiled pdf file can display in Acrobat DC Pro, which is the only software I used to read pdf file. While afterwards, I installed packages bellow , in order to build the Rust Book from Rust's official website, and Comprehensive Rust from google's repo:

mdbook-typst、typst、argo 、mdbook-svgbob 、 mdbook-i18n-helpers 、i18n-report 、 mdbook-exerciser、mdbook-course.

And during this event, I met error that my Windows 10 OS lack font of "Helvetica", So I installed this fonts pack.

And then my Adobe Acrobat DC Pro cannot read the compiled pdf file anymore.

if you know anything conflicts among these packages or this font, please let me know.

It's ok if you have no more advice. Anyway, thanks for your replying.

HollowMan6 commented 3 months ago

Thanks for letting me know more details, it would be appreciated next time if you could post all the details in the beginning to save everyone's time.

Since you are using Windows instead of Linux, and it displays normally in open-source software, I don't think it's caused by the missing fonts, and there should be no conflicts for these packages you mentioned to build the Rust Book from Rust's official website, and Comprehensive Rust from google's repo.

Attached is the book built in Windows generated from CI https://github.com/HollowMan6/mdbook-pdf/actions/runs/9928368120, does that display normally in your Adobe Acrobat Pro?

output.pdf

It works fine on my side when I open it with Adobe Acrobat Pro. As it's closed-source software, I can't give you more suggestions but to upgrade its version.

onbigion13 commented 3 months ago

Yes, the pdf file you built can display in Acrobat DC Pro.

And I can find some thing different. If I open the pdf file I built with Browser, the color density of fonts is lighter than that of fonts when I open the pdf you build with Acrobat.

the effect of the file I build in Edge Browser: image

the effect of the file you build in Acrobat DC Pro: image

I have searched lots of similar problem tonight. I think it's because of the fonts in the built pdf are not correctly embeded within it, or because of that my cargo environment is broken for reason that I install so many packages for build md docs with typst.

it's ok, you can end this issue. I think the eventual problems are that I carelessly delete some font necessary for building Chinese fonts, while I am not sure which are them, or my cargo environment is broken during installing those packages.

onbigion13 commented 3 months ago

By the way, I find that the fonts embeded in pdf file are different.

My "not-normally-displayted" pdf 's fonts: image

Your "normally-displayed" pdf's fonts: image

And my former "normally-displayed" pdf's fonts: image

They are build on the same md docs, which are from the same link, which you also used above.

I'm curious about which fonts are the default ones of "mdbook" and "mdbook-pdf"? Why different pdf files upon the same md docs have different embeded fonts inside? what kind of reasons or configurations of my OS will decide the fonts during building the mdbook pdf files? I will appreciate if you have any idea about this question.

HollowMan6 commented 3 months ago

It's decided by Chrome, we have no control of the fonts to be used in the document.

onbigion13 commented 3 months ago

It's decided by Chrome, we have no control of the fonts to be used in the document.

If there both Chrome and edge in my OS,the font will always be decided by Chrome, right?

HollowMan6 commented 3 months ago

Yes, Chrome has priority over Edge.

https://github.com/rust-headless-chrome/rust-headless-chrome/blob/2fdba7f6f4d9377537efad109780d93f2973c121/src/browser/mod.rs#L525-L535