dompdf doesn't print correctly my custom font

1.8k views Asked by At

I'm having problems on printing the letters of my PDF with my custom font. The script of my Typekit font is embed in my template:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="//use.typekit.net/rhb5dhh.js"></script>
    <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
    <title></title>
  </head>
  <body>
      <div class="tk-museo" style="font-family:museo;">This is a test</div>
  </body>
</html>

It's suppoused to be ok, because I use the class "tk-museo", the one that have in it's css the font.

Some of the settings of the dompdf_config.inc.php are:

- def("DOMPDF_UNICODE_ENABLED", true);
- def("DOMPDF_ENABLE_FONTSUBSETTING", false);
- def("DOMPDF_DEFAULT_FONT", "serif");
- def("DOMPDF_ENABLE_PHP", true);
- def("DOMPDF_ENABLE_JAVASCRIPT", true);
- def("DOMPDF_ENABLE_REMOTE", true);
- def("DOMPDF_ENABLE_CSS_FLOAT", false);
- def("DOMPDF_AUTOLOAD_PREPEND", false);
- def("DOMPDF_ENABLE_HTML5PARSER", false);

Additional info: - I've created a module that generate the PDF with drupal 7

1

There are 1 answers

8
BrianS On

dompdf does not support JavaScript and so can not be used with TypeKit. You'll either need to find a font provider that uses CSS (@font) or allows you to download the fonts.

You only other option is to use a PDF rendering library that supports JavaScript (i.e. a headless browser). Something like PhantomJS.