【问题标题】:mPDF v8.0.4 - Print custom fonts on the PDF filemPDF v8.0.4 - 在 PDF 文件上打印自定义字体
【发布时间】:2021-03-03 03:15:17
【问题描述】:

这个点应该很容易解决,但是三天以来我一直在努力。

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

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

我只是将 Roboto-Regular 打印在 PD 文件上,而不是 Roboto-Thin
非常感谢任何帮助!

文件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&#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;
}

【问题讨论】:

  • 你的 HTML 和 CSS 是什么?
  • 你好@Finwe,我更新了代码。如果你有任何问题,请我在这里。非常感谢您的帮助!

标签: php wordpress pdf woocommerce mpdf


【解决方案1】:

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

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

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

并使用robotoroboto-thin 进行字体系列声明。

【讨论】:

  • 您好@Finwe,非常感谢您的大力帮助。你救了我的一天!它就像一个魅力! ; )
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-09
  • 2017-07-08
  • 2013-02-01
  • 2018-10-27
相关资源
最近更新 更多