Use Custom Fonts with Wkhtmltopdf

use custom fonts with wkhtmltopdf

Since it is a Google Web font you need not to write @font-face in you style sheet just use following link tag in your source code:

<link href='http://fonts.googleapis.com/css?family=Jolly+Lodger' rel='stylesheet' type='text/css'>

and

 <style type = "text/css">
p { font-family: 'Jolly Lodger', cursive; }
</style>

will work.

By the way, in your code you are defining @font-face family as font-family: Jolly; and using it as p { font-family: 'Jolly Lodger', cursive; } that is wrong, because it's mismatching font-family name.

Custom fonts not working in Generated PDF using WKHTMLTOPDF Library

There are multiple solutions to accomplish this:

1) If you use google font, try below:
Use <link> to include google font

<link href='http://fonts.googleapis.com/css?family=YOURFONTFAMILY' rel='stylesheet' type='text/css'>

Use <style> to apply font effect

<style type = "text/css">
p { font-family: 'YOURFONTFAMILY'; }
</style>

2) Encode font with Base64 encode tool and use it in css

@font-face {
font-family: 'YOURFONTFAMILY';
src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}

Hope one of the above is your solution!

Taken ref: use custom fonts with wkhtmltopdf, helvetica font not working in wkhtmltopdf

custom fonts with wkhtmltopdf wrapper nreco on azure web app

This is known issue: Azure Apps hosting environment restricts some GDI APIs and as result wkhtmltopdf cannot load (and render) custom fonts. Only standard fonts that are present on Windows by default could be used (like Arial, Times New Roman etc). You may contact Azure Support on this topic - they could provide more details on the Azure Apps sandbox limitations.

wkhtmltopdf Import font rendering image instead of text

To solve my problem, I installed fonts on my server.
It seems wkhtmltopdf use systems fonts for generation.
If fonts are not found, a pdf image is generated else it generate a pdf text.

helvetica font not working in wkhtmltopdf

The easiest way to fix wkhtmltopdf's font problems is to Base64 encode the font (you can use this tool) and include it in your CSS:

@font-face {
font-family: 'Helvetica';
src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}

This works with all fonts (including Google Fonts), and guarantees cross-platform compatibility across different machines and operating systems.

wkhtmltopdf unicode and custom fonts on server

Problem solved. I did indeed need to upgrade my hosting plan so I could run the wkhtmltopdf static binary with X11. Although the Linux machine only has some Nimbus fonts on it, Arabic and other fonts are working fine for me by adding the font files and using @font-face css rules.

Additional note: to get Arabic text rendering properly using custom Arabic font files, I generated the required font files and css rules using FontSquirrel, with "No subsetting" under "Expert" rendering options.



Related Topics



Leave a reply



Submit