laravellaravel-5controllerfpdffpdi

How to use setasign fpdi v2.0.0 in Laravel 5.2.* or higher?


I want to edit some pdf file with setasign fpdi, When it was fpdi still in version 1.6.* i use this way to use it : I install it via composer

composer require setasign/fpdf & composer require setasign/fpdi

And i use it in Laravel controller :

$pdf = new \FDPI();
$pdf->setSourceFile('PATH/TO/SOURCEFILE');
$pdf->Output();

It work for fpdi version 1.6.* (Legacy)

But when i use the fpdi v2.0.0 and i call the fpdi class in controller using

$pdf = new \FPDI();

it give an error message "Could find FPDI class" from Laravel

Any advice on how to use fpdi v2.0.0 in Laravel5?

Thank you in advance.


Solution

  • Version 2 uses namespaces:

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

    A full migration guide is available here.