如何使用FPDI和TCPDF实现ImageSVG()来呈现PDF?

时间:2016-04-25 16:23:21

标签: php svg tcpdf fpdf fpdi

我正在使用FPDI渲染PDF,其中PDF设置为背景,但希望在其上包含SVG文件,由于某种原因,在使用TCPDF库时会出现错误。是否有任何变通办法或我的代码不正确。

(在我输入“ImageSVG”和“require('tcpdf.php')”行之前,它工作得很好)

这是我的PHP代码:

ob_clean();
ini_set("session.auto_start", 0);
define('FPDF_FONTPATH','font/');
define('FPDI_FONTPATH','font/');
require('fpdf.php');
require('fpdi.php');
require('tcpdf.php');

$pdf = new FPDI();

// let's get an id for the background template
$pdf->setSourceFile('/home/user/public_html'.$pdfName);
$backId = $pdf->importPage(1);

// iterate over all pages of HTML_Generated_pdf.pdf and import them
$pageCount = $pdf->setSourceFile('/home/user/public_html/wp-content/themes/myTheme/'.$filename.'.pdf');
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    // add a page
    $pdf->AddPage($specs['h'] > $specs['w'] ? 'P' : 'L', 'Letter');
    // add the background
    $pdf->useTemplate($backId);
    // import the content page
    $pageId = $pdf->importPage($pageNo);
    // add it
    $pdf->useTemplate($pageId);

    $pdf->ImageSVG($file='images/EN-Logo.svg', $x=30, $y=100, $w='', $h=100, $link='', $align='', $palign='', $border=0, $fitonpage=false);
}

$pdf->Output($filename.'2.pdf', 'F');

我得到的错误:ImageSVG不是FPDI库的方法。

我知道这个方法是我已经包含的TCPDF库的一部分(第7行文本)。有人在乎帮忙吗?

1 个答案:

答案 0 :(得分:2)

删除FPDF require('fpdf.php');的require语句。这样FPDI将扩展TCPDF而不是FPDF。

您也可以删除常量。如果使用TCPDF,则不需要FPDF常量。另外FPDI_FONTPATH它根本就没有使用过,也没有记录,无论如何都要使用。

相关问题