Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

655
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda