【问题标题】:TCPDF weird charecture when converting from SVG file从 SVG 文件转换时的 TCPDF 奇怪的特性
【发布时间】:2016-06-26 06:32:29
【问题描述】:

我在 tcpdf 中遇到字体问题。实际上,我正在从 SVG 文件生成 pdf,对于一些字体,如“alex-brush”,在 pdf 中显示奇怪的字符,如矩形和问号符号。虽然没有显示在 svg 文件中(在浏览器上测试)。

这是我的代码:

require_once ('tcpdf/tcpdf.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', true);

$pdf->SetCreator(PDF_CREATOR);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
$pdf->SetLeftMargin(0);
$pdf->SetRightMargin(0);
$pdf->setPrintFooter(false);
$pdf->setPrintHeader(false);
$pdf->setCellMargins(0,0,0,0);
$pdf->SetCellPaddings(0,0,0,0);
$pdf->SetAutoPageBreak(false);
$pdf->SetDisplayMode(100);

$pdf->AddPage(); // Add page to pdf before addding content
//There are several other property need to be set on basis of your need

$folderName = 'Alex_Brush';
$fontFileName='AlexBrush';

$fontpath = "./tcpdf/fonts/googlefonts/".$folderName."/".$fontFileName."-Regular.ttf";
$fontname = TCPDF_FONTS::addTTFfont($fontpath);
$pdf->SetFont($fontname, '', 14, '', false);
$pdf->setHeaderFont(Array($fontname, '', 10, '', false));
$pdf->setFooterFont(Array($fontname, '', 8, '', false)); 

$pdf->ImageSVG('bpn.svg', $x=0, $y=0, $cwidth, $cheight, '', $align='center', $palign='', $border=0, $fitonpage=TRUE);

$pdf->Output('/home/test/public_html/admin/my.pdf', 'F');

【问题讨论】:

  • 发布一个重现问题的最小 SVG,最好是生成的 PDF 的链接。

标签: svg tcpdf


【解决方案1】:

如果您的 SVG 在您的 text 或 tspan 元素中包含额外的空白(空格、制表符、换行符),TCPDF 可能会将其包含在添加到 PDF 的文本中。

根据字体,这些字符可能会被渲染为“未知”(通常是某种带有问号的框)。

从这些元素中去除空格应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 2016-06-07
    • 2018-03-11
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多