Google Web Fonts and PDF generation from HTML with wkhtmltopdf
To convert HTML to PDF by wkhtmltopdf
try to avoid woff
font face. Use the truetype
format of the Google Web Fonts
with base64
encode.
Recently I tried to use a Google web font from Google Web Fonts. In the browser it shows correctly but it doesn't show after converting HTML to PDF.
After searching the web extensively, at last, I found tools to encode fonts to the base64
format and also got CSS for @font-face
.
Read the solution here.
A simple solution: Base64-encode your font and embed it in the CSS:
@font-face {
font-family: 'OpenSans';
src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}
FontSquirrel can do this for you through the advanced options of their Webfont Generator; Google and other fonts can be encoded with this tool.
I've used this solution with pdfkit
and wicked_pdf
, which work through wkhtmltopdf, so I presume this should work with the native wkhtmltopdf
as well.