Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome headless print-to-pdf doesn't render images

I am trying to write a script to output a lot of markdown pages to PDF using Chrome's headless mode. My current command is:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  --headless  
  --run-all-compositor-stages-before-draw  --disable-gpu 
  --print-to-pdf="index.pdf" http://localhost:8080/#!index.md

The resulting PDF file seems to render as it would be shown except for the images. What I get in the PDF file is a link to the image instead of the image itself.

When I run the --screenshot option I do get the pictures you would expect in the resulting image file.

I think the reason is that it has something to do with the page being rendered with MDwiki, which does a lot of client-side work to convert markdown to HTML. But when I try to use the --virtual-time-budget option Chrome errors out with a message about multiple tables only allowed if debugger is enabled.

Any suggestions for what next to try?

like image 565
AlanObject Avatar asked Dec 03 '25 16:12

AlanObject


1 Answers

It turns out that there is an node package that takes care of this: chrome-headless-render-pdf. There isn't much documentation but it works. Check out:

npm docs chrome-headless-render-pdf
like image 112
AlanObject Avatar answered Dec 06 '25 11:12

AlanObject



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!