Studiosity / grover

A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer/Chromium
MIT License
946 stars 107 forks source link

Generated pdf doesn't contain characters as expected #228

Closed mehroz-muzaffar-32 closed 8 months ago

mehroz-muzaffar-32 commented 8 months ago

Okay so I came across this gem and I think it's amazing. While playing around with it I found an issue while generating pdf for some characters. I did some digging and found that it uses puppeteer under the hood for generating pdf. So, I tried to generate the pdf for same characters directly using puppeteer and it correctly generated the pdf with characters intact.

I am currently using: grover version 1.1.6 puppeteer version 21.5.2

The characters in question: ÁáÉéÍíÑñÓóÚúÜü¿¡ªº

With grover I got this in the pdf:

image

But by directly using puppeteer I got this in the pdf:

image
abrom commented 8 months ago

I'm not sure you should have needed to do any digging to find that out?? It's in the first line of the README!

A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer and Chromium.

Anyway, to your issue.. this appears to be a content encoding problem. You haven't really gone into any detail to explain how you can replicate the issue.. however I can replicate your issue if I do something like:

Grover.new('<html><body>ÁáÉéÍíÑñÓóÚúÜü¿¡ªº</body></html>').to_pdf

BUT.. it works just fine if I tell Grover (puppeteer/chromium) what the content encoding is 😄 (ie add <meta charset="utf-8"> to the page head..)

Grover.new('<html><head><meta charset="utf-8"></head><body>ÁáÉéÍíÑñÓóÚúÜü¿¡ªº</body></html>').to_pdf

HTH

mehroz-muzaffar-32 commented 8 months ago

Hey @abrom, thanks for the working solution and also sorry for my bad English. I did actually saw puppeteer in readme. I guess it was just poor choice of words by me😅.

abrom commented 8 months ago

not a problem 😄 I was just wanting to make sure the documentation was ok!