Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

659
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda