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:

  1. Navigate to the font of your choice.
  2. On the font page, select all of the styles you want to use in your PDF.
  3. In the "Selected family" details, copy the <link> tag and CSS rules, for use in your PDF's HTML.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.