2017-10-18 75 views
-1

我如何強制mpdf生成PDF與泰晤士報新羅馬字體?使用時間新的羅馬字體與mpdf

include("mpdf/mpdf.php"); 
$mpdf=new mPDF('utf-8'); 

$mpdf->WriteHTML($html); 
$mpdf->Output(); 

的$ HTML包含簡單的HTML頁面:

<html> 
<head> 
<style> 
body { 
font-family: 'Times New Roman'; 
} 

</style> 
</head> 
<body> 
<p>Hello World</p> 
</body> 
</html> 

回答

0

使用以下:

<?php 
$mpdf = new Mpdf([ 
    'default_font' => 'Times New Roman' 
]); 

但是對於HTML,你可以嘗試內嵌代替:

<body style="font-family: Times New Roman;"> 

更多關於它Default Font

編輯:看來Times New Romanmpdf默認不可用,所以你將不得不單獨download並使用類似:

$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults(); 
$fontDirs = $defaultConfig['fontDir']; 

$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults(); 
$fontData = $defaultFontConfig['fontdata']; 

$mpdf = new \Mpdf\Mpdf([ 
    'fontDir' => array_merge($fontDirs, [ 
     __DIR__ . '/custom/font/directory', 
    ]), 
    'fontdata' => $fontData + [ 
     'frutiger' => [ 
      'R' => 'timesnewroman.ttf' 
     ] 
    ], 
    'default_font' => 'timesnewroman' 
]); 

而在你的HTML做到:

<body style="font-family: timesnewroman;">