Can I use web fonts with generated PDFs?
Absolutely! Besides improving aesthetics, this technique is critical for properly displaying non-Latin languages.
We've put together a demonstration task that allows you to see this in action, using a typeface from Google Fonts: see Demonstration: Web fonts in PDFs.
To use a custom web font, add its <link>
tag to your PDF's HTML, and use a <style>
tag to apply your font your content, like this:
<link href="https://fonts.googleapis.com/css2?family=Liu+Jian+Mao+Cao&display=swap" rel="stylesheet"> <style> p { font-family: 'Liu Jian Mao Cao', cursive; } </style> <p>Almost before we knew it, we had left the ground.</p>
To retrieve the appropriate code from Google Fonts, follow these steps:
- Navigate to the font of your choice.
- On the font page, select all of the styles you want to use in your PDF.
- In the "Selected family" details, copy the
<link>
tag and CSS rules, for use in your PDF's HTML.