2017-10-09 74 views
0

我有一個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文件

回答

0

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>