Reputation: 9476
I am using composer installation of DomPDF. so i can't use custom font. I have used font-face option but font is not applying in PDF.
$dompdfOptions->set('fontDir', CSSPATH);// for default fonts
$dompdfOptions->set('fontDir', FONTSPATH);// for custom fonts
$dompdfOptions->set('defaultMediaType', 'all');
$dompdfOptions->set('isFontSubsettingEnabled', true);
$dompdf = new Dompdf($dompdfOptions);
but font is not apply.
if i following style:
"font-family: Georgia;" // Georgia is example
not working but if i use
"font: 24px Georgia;"
font is working but if i add font styles like italic/bold, again it is not working.
Please let me know what is issue in this.
Thanks
Upvotes: 0
Views: 8269
Reputation: 11
For your custom font issue, mpdf is better than DomPDF and others. it has following features
How to add new fonts with mpdf
Upvotes: 0
Reputation: 7
Use css and it worked. we need to use font instead of font-family in css.
@font-face{
font-family: myFontName;
src:url('http:://yourwebsite.com/myFontName.ttf');
}
p{
font: myFontName;
}
Upvotes: 0
Reputation: 957
I have created demo to use Custom Fonts
in DomPDF
.
<?php
$html = '<!DOCTYPE html>
<html lang="en" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>DUMMY DOM PDF</title>
<style>
@import url("https://fonts.googleapis.com/css?family=Joti+One");
.joti-font {font-family: "Joti One", cursive;}
</style>
</head>
<body>
<div class="joti-font">This is Test PDF</div>
</body>
</html>';
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream("codex",array("Attachment"=>0));
?>
Upvotes: 3