NoReceipt4Panda NoReceipt4Panda - 1 year ago 198
PHP Question

How to implement ImageSVG() using FPDI and TCPDF to render PDF?

I'm using FPDI to render a PDF that has a PDF set as a background, but want to include an SVG file on it, which for some reason gives me the error while using the TCPDF library along with it. Are there any workarounds, or my code incorrect.

(before I put in the "ImageSVG" and "require('tcpdf.php')" lines, it was working perfectly)

Here's my PHP code:

ini_set("session.auto_start", 0);

$pdf = new FPDI();

// let's get an id for the background template
$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
// import the content page
$pageId = $pdf->importPage($pageNo);
// add it

$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');

The error I'm getting: ImageSVG not a method of FPDI library.

I know that this method is part of the TCPDF library, which I have already included (7th line of text). Anyone care to help?

Answer Source

Remove the require statement for FPDF require('fpdf.php');. That way FPDI will extend TCPDF instead of FPDF.

You also can remove the constants. If you use TCPDF you don't need a constant of FPDF. Additionally FPDI_FONTPATH it's never used nor documentated at all and uselsee in any case.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download