Print HTML containing Font Awesome icons with wkhtmltopdf
Asked Answered
A

3

6

I want to print an HTML page, that contains Font Awesome icons, with wkhtmltopdf. I saw this issue with Google fonts: Google Web Fonts and PDF generation from HTML with wkhtmltopdf, but this way is not working.

Arena answered 28/7, 2014 at 12:37 Comment(0)
W
0

Add the .woff file in your Font Awesome lib dir (no base64 in css) and it should work.

Wakerly answered 30/7, 2014 at 12:30 Comment(1)
Can you explain this further with an example?Impressionist
I
6

I solved this by inlining the TTF version of the file like this:

<style type="text/css">
@font-face {
    font-family: 'FontAwesome';
    src: url(data:application/x-font-truetype;base64,<< insert base64 encoded fontawesome-webfont.ttf here >>) format('truetype');
    font-weight: normal;
    font-style: normal;
}
</style>

And then inlining the font-awesome.css file. BUT you need to remove the @font-face at-rule of that file, since wkhtmltopdf doesn't like multiple @font-faces that define the same font. You can do that by either inlining a modified version of the file or by using a RegEx to remove the at-rule (e.g.: @font-face\s*\{[^\}]*\}).

(I tried leaving the original @font-face intact, hoping a later definition would overwrite it, but that didn't work. The CSS standard doesn't seem to define what happens when two @font-face for the same font appear, if I read it correctly)

Inbound answered 12/1, 2018 at 7:54 Comment(1)
Worked for me too with headless chromium print to pdf. Thanks!Substituent
N
2

Do you have any examples ??

I saw something similar in this issue: https://github.com/mileszs/wicked_pdf/issues/587

The filename contains a carriage return character, which is not a valid display symbol. The glyph you're seeing is one usually research for private Unicode character areas.

Narine answered 30/6, 2017 at 18:22 Comment(1)
I have the same problemArleanarlee
W
0

Add the .woff file in your Font Awesome lib dir (no base64 in css) and it should work.

Wakerly answered 30/7, 2014 at 12:30 Comment(1)
Can you explain this further with an example?Impressionist

© 2022 - 2024 — McMap. All rights reserved.