TransWikia.com

Custom font bold weight not working in Dompdf

Stack Overflow Asked by user13286 on September 17, 2020

I am using Dompdf to generate and send a PDF via email from my WordPress site. I am attempting to use a custom font and the normal font-weight is working correctly, but bold is not.

Here’s what my HTML variable looks like:

$html =
'<html>
  <body>
    <style>
    @font-face {
      font-family: "Proxima Nova";
      font-weight: normal;
      font-style: normal;
      src: url(' . get_template_directory() . '/fonts/ProximaNova-Reg.woff2) format("woff2"), url(' . get_template_directory() . '/fonts/ProximaNova-Reg.woff) format("woff");
    }
    @font-face {
      font-family: "Proxima Nova";
      font-weight: bold;
      font-style: normal;
      src: url(' . get_template_directory() . '/fonts/ProximaNova-Bold.woff2) format("woff2"), url(' . get_template_directory() . '/fonts/ProximaNova-Bold.woff) format("woff");
    }
    body,html {font-family:"Proxima Nova";}
    </style>
    <table>
      <thead>
        <tr>
          <th>Test</th>
          <th>Test</th>
          <th>Test</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Test</td>
          <td>Test</td>
          <td>Test</td>
        </tr>
      </tbody>
    </table>
  </body>
</html>';

When I open the generated PDF, the tds are correctly displayed in the Proxima Nova font, but the ths are not. The weird thing is that if I just email the HTML to myself using wp_mail the bold font works correctly. It’s only in the PDF that it doesn’t work. Any ideas?

Screenshot from the email:
enter image description here

Screenshot from the PDF:
enter image description here

I do not have the font installed locally

One Answer

I figured out the issue, at one point I was using the TrueType version of the normal font weight but not the bold. Apparently php-font-lib can only generate the compatible fonts from a ttf file and not woff. When I switched both declarations over to ttf it generated the necessary files and now both weights are working.

Answered by user13286 on September 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP