从SVG文件转换时TCPDF怪异的charecture

时间:2016-03-11 05:37:10

标签: svg tcpdf

我在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');

1 个答案:

答案 0 :(得分:0)

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

根据字体的不同,这些字符可能会被渲染为"未知" (通常是某种带问号的盒子)。

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