当使用TCPDF转换为PDF时,SVG变量显示未定义的索引
问题描述:
我有一个SVG文件。我试图使用TCPDF作为PDF文件下载。如果SVG文件中没有#
,那么SVG将转换为PDF。问题是文件'#'。请告诉我该怎么做。当使用TCPDF转换为PDF时,SVG变量显示未定义的索引
canvas.svg:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1140" height="600" viewBox="0 0 1140 600" xml:space="preserve">
<desc>Created with Fabric.js 1.7.17</desc>
<defs>
</defs>
<rect x="0" y="0" width="1140" height="600" fill="#ffffff"></rect>
<g clip-path="url(#clipCircle)">
<image xlink:href="http://localhost/canvas/560.jpg" x="-235" y="-280" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" width="470" height="560" preserveAspectRatio="none" transform="translate(235 280)"></image>
</g>
<clipPath id="clipCircle"><rect x="50" y="120" width="670" height="320" rx="40" ry="40"></rect></clipPath></svg>
pdf.php:
这是我使用的下载文件为PDF文件。
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetMargins(10, 10, 10, true);
// set font
$pdf->SetFont('helvetica', '', 10);
// add a page
$pdf->AddPage();
$pdf->ImageSVG($file='images/canvas.svg', $x=30, $y=100, $w='', $h=100, $link='', $align='', $palign='', $border=0, $fitonpage=false);
//Close and output PDF document
$pdf->Output('canvasoutput.pdf', 'D');
错误:
说明:未定义指数:clipCircle在d:\ XAMPP \ htdocs中\帆布\ TCPDF \上线tcpdf.php 23043
警告:提供的foreach无效的参数() D:\ xampp \ htdocs \ canvas \ TCPDF \ tcpdf.php on line 23044 TCPDF ERROR:有些数据已经输出,无法发送PDF文件
答
svg文件在网页中工作,但没有当我转换为PDF.I发现问题。其实clipPath
应包含在defs
。这是首选的解决方案。它也适用于TCPDF。
canvas.svg:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1140" height="600" viewBox="0 0 1140 600" xml:space="preserve">
<desc>Created with Fabric.js 1.7.17</desc>
<defs>
//added Here
<clipPath id="clipCircle"><rect x="50" y="120" width="670" height="320" rx="40" ry="40"></rect></clipPath>
</defs>
<rect x="0" y="0" width="1140" height="600" fill="#ffffff"></rect>
<g clip-path="url(#clipCircle)">
<image xlink:href="http://localhost/canvas/560.jpg" x="-235" y="-280" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" width="470" height="560" preserveAspectRatio="none" transform="translate(235 280)"></image>
</g>
</svg>