Kermit
Kermit

Reputation: 34062

How can I extend TCPDF with FPDF and FPDI?

I'm trying to extend FPDF with FPDI and TCPDF.

require('./fpdf/fpdf.php');
require('./tcpdf/tcpdf.php');
require('./fpdi/src/autoload.php');

$pdf = new \setasign\Fpdi\Fpdi();

...
$pdf->setSourceFile(...); // from FDPI
$pdf->ImageSVG(...); // from TCPDF
...

Which gives me

Fatal error: Uncaught Error: Call to undefined method setasign\Fpdi\Fpdi::ImageSVG()

I have tried this answer by:

require('./tcpdf/tcpdf.php');
require('./fpdi/src/autoload.php');

$pdf = new FPDI();

...
$pdf->setSourceFile(...); // from FDPI
$pdf->ImageSVG(...); // from TCPDF
...

And I get the error:

Fatal error: Uncaught Error: Class 'FPDI' not found

I also tried this answer by:

require('./tcpdf/tcpdf.php');
require('./fpdi/src/autoload.php');

$pdf = new \setasign\Fpdi\Fpdi();

...
$pdf->setSourceFile(...); // from FDPI
$pdf->ImageSVG(...); // from TCPDF
...

And I get the error:

Fatal error: Class 'FPDF' not found

Any guidance is appreciated.

Upvotes: 0

Views: 2600

Answers (1)

Jan Slabon
Jan Slabon

Reputation: 5058

FPDI comes with a class that already extends TCPDF:

require('./tcpdf/tcpdf.php');
require('./fpdi/src/autoload.php')

$pdf = new setasign\Fpdi\Tcpdf\Fpdi();

This is documented here.

Upvotes: 2

Related Questions