1
votes

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

1
Try setting an explicit style of th{font-weight: bold;} to see if that kicks it in.Chris Haas

1 Answers

2
votes

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.