maghfirzakir maghfirzakir - 6 months ago 140
CSS Question

Bold Font for dompdf 0.7.0 beta

I'm using DOMPDF ver. 0.7.0 to make a pdf file from HTML, but I have problem when I need to use custom font (arial) with bold style. the bold font won't work after rendering.

here's the CSS style I'm using now:

@font-face {
font-family: 'font';
font-style: normal;
font-weight: normal;
src: url(dompdf/font/arial.ttf);
}

@font-face {
font-family: 'font';
font-style: normal;
font-weight: bold;
src: url(dompdf/font/arialbd.ttf);
}
body{
font-family: 'font';
}


and here's dompdf - php code:

require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
file_put_contents('pdf/sptjm.pdf', $pdf)


here's the result in HTML:
enter image description here

and here's the result in PDF:
enter image description here

the pdf didn't show the bold type, please help. thanks in advance.

Answer

i have done it simply with using different font name:

@font-face {
    font-family: 'font';
    font-style: normal;
    font-weight: normal;
    src: url(dompdf/font/arial.ttf);
}

@font-face {
    font-family: 'font2';
    font-style: normal;
    font-weight: bold;
    src: url(dompdf/font/arialbd.ttf);
}
body{
    font-family: 'font';
}

so when i need the bold font type, just simply call the other font name 'cuz basically it is different font source.

Comments