dompdf未生成.ufm和dompdf_font-family_cache.php文件
我试图在生成 pdf 文件时在 dompdf 中使用自定义字体。我发现自定义字体仅在生成 .ufm 和缓存文件后才有效。
Drupal php 文件
public function GeneratePdf() {
$dompdf = new Dompdf();
$fontDirectory = $host.'/'.$themepath . '/fonts';
$options->setChroot($fontDirectory);
$dompdf->setOptions($options);
ob_end_clean();
$dompdf->getFontMetrics()->registerFont(
['family' => 'montserrat', 'style' => 'normal', 'weight' => 'normal'],
$fontDirectory . '/Montserrat-Regular.ttf'
);
$dompdf->loadHtml($html);
$dompdf->render();
ob_end_clean();
}
Pdf 生成 HTML .twig 文件。
<html>
<head>
<style type="text/css">
@page {
size: auto;
margin: 0;
padding: 0;
}
@font-face {
font-family: montserrat;
src: url($themepath ~'/fonts/Montserrat-Regular.ttf') format('truetype'); font-style: normal;
}
</style>
</head>
<body style="margin:0; padding:0;">
<span style="font-family:'montserrat';color:#417bac; font-size:18px">PDF font testing</span>
</body>
</html>
问题是通过 php 函数注册字体后所需的文件,即 .ufm 和 dompdf_font-family_cache.php 未在 dompdf 文件夹中创建 >供应商\dompdf\dompdf\lib\字体
I am trying to use custom font in dompdf while generating pdf file. As i found that custom font works only after generating .ufm and cache file.
Drupal php file
public function GeneratePdf() {
$dompdf = new Dompdf();
$fontDirectory = $host.'/'.$themepath . '/fonts';
$options->setChroot($fontDirectory);
$dompdf->setOptions($options);
ob_end_clean();
$dompdf->getFontMetrics()->registerFont(
['family' => 'montserrat', 'style' => 'normal', 'weight' => 'normal'],
$fontDirectory . '/Montserrat-Regular.ttf'
);
$dompdf->loadHtml($html);
$dompdf->render();
ob_end_clean();
}
Pdf generation HTML .twig file.
<html>
<head>
<style type="text/css">
@page {
size: auto;
margin: 0;
padding: 0;
}
@font-face {
font-family: montserrat;
src: url($themepath ~'/fonts/Montserrat-Regular.ttf') format('truetype'); font-style: normal;
}
</style>
</head>
<body style="margin:0; padding:0;">
<span style="font-family:'montserrat';color:#417bac; font-size:18px">PDF font testing</span>
</body>
</html>
Issue is after registering font through php function required files i.e .ufm and dompdf_font-family_cache.php not created in dompdf folder vendor\dompdf\dompdf\lib\fonts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论