Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

654
Views
Fonts work in HTML but not rendered PDF Dompdf v0.8.0

I realize there is a whole host of somewhat related topics, but I just can't seem to find one that's the same and / or includes a solution that solves my problem.

I'm sending an HTML document to dompdf which includes embeded CSS and includes font-face declarations and class definitions. The fonts are on the same server and I've tried with both relative and absolute paths and can't seem to get them to work.

I'm including the following in the head of the HTML document I then send to dompdf.

<style type="text/css">
    @font-face {
        font-family: "Roboto";
        font-weight: normal;
        font-style: normal;
         src: url( "http://localhost/resources/fonts/Roboto/Roboto-Regular.ttf") format('truetype');
     }
      .font_alpha { font-family: "Roboto";}`

    /* .... Other css rules here ... */

</style>

When I echo the html rather than send it on to dompdf I can see that the font for any element with the .font_alpha class applied is correct, in inspector it also shows that it's using the network resource yet when I call the following on the html, the font doesn't get applied.

//This is where I would display the html directly for testing
//echo $report_html; exit;

$dompdf = new DOMPDF();
$dompdf -> load_html( $report_html );
$dompdf -> set_paper( $this -> paper_size, $this -> paper_orientation );
$dompdf -> render();
$dompdf -> output();

The pdf(s) get generated correctly with all css formating from the rest of the rules being correctly applied except for the fonts.

To be honest, I'm not sure if I need to be installing these fonts in an additional way like using cmd line load_font.php thirdparty lib or not. Based on what I believe I can understand about version 0.8.0, I shouldn't need to, correct?

Any advice or input?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Dompdf's CSS parsing logic can be a bit finicky. The space in front of the URL string is tripping Dompdf up. If you modify your CSS to read src: url("http...") format('truetype'); it should work as expected.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!