简体   繁体   中英

DOMPDF set font for entire page?

Im using DOMPDF over at http://dompdf.github.com/

I am struggling how to set the font for the entire page. In the template I have made I have the font set to Helvetica in the CSS but when it generates the PDF it defaults to Times New Roman. When I try

<script type="text/php">{literal}if ( isset($pdf) ) { 
    $font = Font_Metrics::get_font("helvetica", "bold");
    $pdf->page_text(72, 18, "TEST!", $font, 6, array(0,0,0));}
{/literal}</script>

It prints the TEST! text in the font. However how do I get it to apply to the whole page?

Thanks

DOMPDF works with CSS so you need to set the font family like so:

body {  
    font-family: 'Helvetica'  
}

BUT remember that you can only use the font that have been installed. To check which fonts you can use have a look in the fonts directory: /dompdf/lib/fonts/

To install more font follow this guide: http://code.google.com/p/dompdf/wiki/Installation#Font_Installation

DOMPDF supports CSS, so you can just define the font in your CSS file and load it like you normally would on a page:

body {
    font-family: 'Helvetica'
}

I had the same problem. Somehow DomPDF has trouble with the font-family definition in the CSS. I applied inline style to the top div box to solve the problem.

<div id="container" style="font-family:sans-serif;">
....
</div>

Hope this works for anyone still reading this thread.

You need to add the font-family definition to every element in your CSS:

body, #wrapper, #content {
font-family:sans-serif;
}
table{
font-family:sans-serif;
}     
table tr{
font-family:sans-serif;
}    
table td{
font-family:sans-serif;
}        
a:link, a:visited {
font-family:sans-serif;
}
p {
font-family:sans-serif;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM