mPDF v8.0.4 - 在 PDF 文件上打印自定义字体
mPDF v8.0.4 - Print custom fonts on the PDF file
1°这个问题应该很容易解决,但是三天以来我一直在努力
2°我只需要在PDF Roboto-Regular和Roboto-thin中使用两种字体。
3°我已经阅读了手册,但不幸的是我仍然做错了或者文件中缺少一些东西
文档:https://mpdf.github.io/fonts-languages/font-names.html
4° 我刚在 PD 文件上打印了 Roboto-Regular,但不是 Roboto-瘦
非常非常感谢任何帮助!
文件testmpdf.php
// Load MPDF Loader
require_once __DIR__ . '/vendor/autoload.php';
use Mpdf\Mpdf;
$mpdf = new Mpdf();
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf= new \Mpdf\Mpdf(
['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ã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',
]
],
并使用 roboto
和 roboto-thin
进行字体系列声明。
1°这个问题应该很容易解决,但是三天以来我一直在努力
2°我只需要在PDF Roboto-Regular和Roboto-thin中使用两种字体。
3°我已经阅读了手册,但不幸的是我仍然做错了或者文件中缺少一些东西
文档:https://mpdf.github.io/fonts-languages/font-names.html
4° 我刚在 PD 文件上打印了 Roboto-Regular,但不是 Roboto-瘦
非常非常感谢任何帮助!
文件testmpdf.php
// Load MPDF Loader
require_once __DIR__ . '/vendor/autoload.php';
use Mpdf\Mpdf;
$mpdf = new Mpdf();
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/custom/temp/dir/path']);
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf= new \Mpdf\Mpdf(
['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ã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',
]
],
并使用 roboto
和 roboto-thin
进行字体系列声明。