Bhumi Shah
Bhumi Shah

Reputation: 9476

Custom Font issue in DomPDF latest version 0.8.2

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

Answers (3)

Chanaka
Chanaka

Reputation: 11

For your custom font issue, mpdf is better than DomPDF and others. it has following features

  1. add new fonts
  2. Full Unicode support
  3. Complex scripts support 3.1 Right-to-left languages (Hebrew, Arabic etc.)Permalink 3.2 Indic languages, Lao, Tibetan etc 3.3 Vertical writing
  4. TrueType Collections
  5. Unicode Supplementary Planes

How to add new fonts with mpdf

  1. Add your font directory to fontDir configuration parameter or by calling $mpdf->AddFontDirectory() method
  2. Define the font file details in the fontData parameter array
  3. Access the font by specifying it in your HTML code as the CSS font-family
  4. Specifying languages for the font by defining custom Mpdf\Language\LanguageToFontInterface and Mpdf\Language\ScriptToLanguage implementation

Upvotes: 0

Md Rukon Shekh
Md Rukon Shekh

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

Harsh Barach
Harsh Barach

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));
?>

enter image description here

Upvotes: 3

Related Questions