【发布时间】:2018-08-25 21:58:00
【问题描述】:
我有一个使用画布和 FabricJS 构建的图形编辑器。我将 SVG 输出到服务器,然后使用 TCPDF 库创建包含 SVG 文件的 PDF。然而,大部分要点都从 PDF 中删除,尽管它们出现在 SVG 中(参见下面的屏幕截图)。我一直在寻找解决方案几个小时,但我能想到的只是它正在删除项目符号,因为它不是 UTF8 字符并且不包含在我们正在使用的自定义字体系列中。项目符号似乎只适用于标准字体系列。
我见过几种使用 TCPDF 创建项目符号的方法,但是它们都没有处理 SVG 文件中的项目符号。非常感谢任何帮助!
另外,这里是生成 PDF 的 PHP 代码:
require(PATH TO TCPDF."/tcpdf.php");
$width = $brochure_data["total_width_inches"];
$height = $brochure_data["total_height_inches"];
$orientation = ($height>$width) ? 'P' : 'L';
$page_size = array($width, $height);
$pdf = new TCPDF($orientation, "in", $page_size, true, 'UTF-8', false);
//Import custom fonts
$fonts=get_fonts();
foreach($fonts AS $font){
if($font["font_source"]){
TCPDF_FONTS::addTTFfont(PATH TO FONTS."/".$font["font_source"], 'TrueType', '', 32);
}
}
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set margins
$pdf->SetMargins(0, 0, 0, true);
// set auto page breaks false
$pdf->SetAutoPageBreak(false, 0);
//Loop through each SVG and create a new page for each
foreach($svg_images AS $svg_image){
// add a page
$pdf->AddPage($orientation, $page_size);
$pdf->ImageSVG($svg_image, $x=0, $y=0, $w=$brochure_data["total_width_inches"]*300, $h=$brochure_data["total_height_inches"]*300, $link='', $align='', $palign='', $border=0, $fitonpage=true);
}
//Close and output PDF document
$pdf_filename=BROCHURE FILENAME.".pdf";
$pdf->Output($pdf_filename, 'F');
这是来自 SVG 文件的 sn-p。如果字体系列是 Arial 或标准字体,但不是使用指定的字体,项目符号将起作用。
<g transform="translate(714 287.2896)"> <text font-family="Lobster" font-size="24" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(51,51,51); fill-rule: nonzero; opacity: 1;" > <tspan x="-63.61" y="-8.17" fill="#333333">• Demo Text</tspan> <tspan x="0" y="23.29" fill="#333333"></tspan> </text> </g>
【问题讨论】:
-
在this discussion 中,开发人员声明不支持某些“高级文本”功能。但是,自 2012 年以来,这可能已经发生了变化。您能否发布一个触发该问题的 SVG 源代码的小示例?
-
我在问题中添加了一个 sn-p。