添加非默认字体时,DomPdf无法对齐文本

时间:2016-01-22 17:36:50

标签: php fonts dompdf text-align

我正在尝试创建一个小应用程序,其中一个模块应该打印公司徽章,我创建了一个仅用于测试的基本代码,但图像正在居中,但文本没有。

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Carnets</title>
</head>
<body>
<?php

require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;

$html = 
'<table style="height: 506.5px; width: 319px;" border="0" align="center">
<tbody>
<tr>
<td align="center"><img src="archivos\logo.jpg" alt="logoAig"/><br><br><br></td>
</tr>
<tr>
<td align="center"><img src="archivos\USUARIO.jpg" width="300" height="300" alt="usuario"/><br><br><br><br></td>
</tr>
<tr>
<td style="text-align:center;"><span style="font-family: aigfuturamed; font-size: 32; color: rgb(0,164,228);">NAME</span></td>
</tr>
<tr>
<td style="text-align:center;"><br><br><span style="font-family: aigfuturamed; font-size: 24; color: rgb(0,164,228);">LASTNAME</span></td>
</tr>
</tbody>
</table>';

function creaCarnet($html){
    // instantiate and use the dompdf class
    $html = '<html><body>'.$html.'</body></html>';
    $dompdf = new Dompdf();
    $dompdf->loadHtml($html);

    // (Optional) Setup the paper size and orientation
    $dompdf->setPaper(array(0,0,319,506.5), 'portrait'); 

    // Render the HTML as PDF
    $dompdf->render();

    // Get the generated PDF file contents
    $pdf = $dompdf->output();

    // Output the generated PDF to Browser
    $dompdf->stream();
}

//echo $html;
creaCarnet($html);
?>



</body>
</html>

在网站上显示HTML时,所有单词都居中,但打印PDF时根本不起作用。我在这里错过了什么?我使用的字体是Futura的特殊版本,如果我使用任何其他字体或不选择字体特别是问题仍然显示,请不要介意。

dompdf的版本是:0.6.2

关于这个问题的新信息,我开始新鲜,没有我之前运行过的所有其他测试并创建了一个新文件,它在计数方面做得很好,它确实对齐了文本。然而,当我添加新字体是现在的问题,如果我去使用任何标准默认字体我没有问题,但因为当我去选择字体时公司政策要求使用这种特殊字体“ aigfuturamed“我使用load_font.php创建的,当我遇到问题时。

这是关于dompdf_font_family_cache.dist的补充信息:

'aigfuturamed' => array ( 'normal' => DOMPDF_FONT_DIR . 'AIGFutura-Medium', 'bold' => DOMPDF_FONT_DIR . 'AIGFutura-Medium', 'italic' => DOMPDF_FONT_DIR . 'AIGFutura-Medium', 'bold_italic' => DOMPDF_FONT_DIR . 'AIGFutura-Medium', ),

这是目前的结果: Card incorrectly showing font to the left instead of center

这是我想要的结果: And this is how it should look

0 个答案:

没有答案