3

I'm trying to generate a PDF via wkhtmltopdf in an Amazon Linux os, everything works fine, but when i try to use emoji on the HTML, the fonts break and the emoji is displayed as a black box. Before deploying, i tried locally and it works, locally i have Ubuntu, so my guess is that i'm missing something (fonts?) in the production (the amazon linux instance) server. I tried to install Google Noto font but nothing happened. I'll attach 2 screens of the same HTML page, generated by the same command via wkhtmltopdf:

Local (Ubuntu): Local Image

Production (Amazon Linux): Production Image

As you can see, even the font below the broken emoji is not rendered as aspected, i'll add the command i use in both servers:

/my/path/to/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality 'file:///my/path/to/page-test-pdf.html' '/home/user/test.pdf'

Thanks for your time.

Community
  • 1
  • 1
Gumma Mocciaro
  • 1,205
  • 10
  • 24

2 Answers2

1

If you are running PHP 7.x, I have been having problems with the wkhtmltopdf extension within a dockerized image. We were trying to use font awesome and the text just did not render correctly. There were some compilation issues that caused this.

The problem was resolved when using the following binary https://github.com/madnight/docker-alpine-wkhtmltopdf

Hope this helps you forward.

EDIT: You will also have to have all fonts used installed as system fonts iirc otherwise wkhtmltopdf will refuse to work as it cannot find the font

Matt Smeets
  • 398
  • 4
  • 15
  • unfortunately i need to use emoji because i need to generate a report for some push notifications (containing emoji), i actually refuse to map every emoji and replace it with something else, i think i need to install the right fonts in the server, moreover, i'll try the binary you linked instead the one i got from composer (i don't use docker in this project, but i guess this will not be a problem), thanks! – Gumma Mocciaro Nov 23 '18 at 09:41
  • I tried to use that binary but unfortunately is for 32bit OS, while i have 64Bit. I also tried to install the fonts in the server but it didn't help either. I wrote in the project's github so i'll just wait and hope – Gumma Mocciaro Nov 23 '18 at 10:51
1

You can find a solution to a similar issue here basically twemoji.min.js replace the emoji with the corresponding image. Regarding the weird font spacing issue, you can use a monospaced font like roboto mono or something you like.

panza
  • 26
  • 3