mPDF v8.0.4-在PDF文件上打印自定义字体



这一点应该很容易解决,但我已经三天在努力了。

我只需要在PDF Roboto Regular和Roboto thin中使用两种字体。

我已经阅读了手册,但不幸的是,我仍然做错了,或者文件中缺少一些内容
文档:https://mpdf.github.io/fonts-languages/font-names.html

我刚刚在PD文件上打印了Roboto Regular,但没有打印Roboto Thin
任何帮助都非常非常感谢!

文件testmpdf.php

// Load MPDF Loader
require_once __DIR__ . '/vendor/autoload.php';
use MpdfMpdf;
$mpdf = new Mpdf();
$mpdf = new MpdfMpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);
$defaultConfig = (new MpdfConfigConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new MpdfConfigFontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf= new MpdfMpdf(
['mode' => 'utf-8',
'format' => 'A4',
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
'margin_header' => 0,
'margin_footer' => 0,
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/assets/css/fonts',
]),
'fontdata' => $fontData + [
'roboto' => [
'R' => 'Roboto-Regular.ttf',
'I' => 'Roboto-Thin.ttf',
]
],
'default_font' => 'roboto'
]); //use this customization

HTML部件

$html = '
<div class="bkg_div">
<p><img style="margin-top:20px;margin-left:35px;" src="images/silhouette_office.png" width="80" /></p>
<p style="font-family:roboto;font-weight:900;font-size: 30px;color: #ffffff;text-transform: uppercase;margin-left:35px;">BOOKING INVOICE</p>
<p style="margin-left:35px;font-family:Roboto-thin;font-weight:100;">Gratid&#227;o '.$username.'. Your order has been ordered. We sent the proof of purchase by email to you.<br/>
Order Booking Time: <b>48 hours</b> - Please make payment now before you lose your reservation!<br/>
</p>  
</div>

CSS文件

li.woocommerce-order-overview__payment-method.method{
background: #C8D2D9;
padding: 5px;
width: 80%;
position: relative;
border-bottom: 3px dotted #ECEFF1 !important;
border-radius: 0px 0px 24px 24px;
text-align: center;
margin: 0px 50px 0px 50px; 
font-family:'Roboto-thin',sans-serif;
font-weight:100;
letter-spacing: 0.04em;    
}
.font_p1 {
font-weight:400;
font-size: 30px;
font-family: Roboto, sans-serif;
color: #ffffff;
text-transform: uppercase;
}

由于您的字体是在mPDF实例化中定义的,因此通常需要使用font-family: roboto(注意小写(,而斜体用于Roboto Thin。

或者,定义两个字体系列:

'fontdata' => $fontData + [
'roboto' => [
'R' => 'Roboto-Regular.ttf',
],
'roboto-thin' => [
'R' => 'Roboto-Thin.ttf',
]
],

并使用CCD_ 2和CCD_。

最新更新