2

Hello I'm using Fpdi class to add an Image on a pdf file (in PHP) (I downloaded code from github https://github.com/Setasign/FPDI)

But when i try instantiate a new Fpdi, I get the error: Class 'Fpdi' not found at line $pdf = new Fpdi();

Here is my code:

<?php
    //I don't get any error like require_once(): Failed opening required so I guess the files exist 
    require_once "fpdf.php";
    require_once "FPDI/src/autoload.php";
    require_once "FPDI/src/Fpdi.php";

    $test = new FPDF();
    echo '<br><br>';
    //no probleme here
    var_dump($test);
    echo '<br><br>';
    //I can see the files I want to include (fpdf.php,FPDI/src/autoload.php,/FPDI/src/Fpdi.php,FPDI/src/FpdfTpl.php,FPDI/src/FpdiTrait.php)
    print_r(get_required_files());
    echo '<br><br>';
    //error here
    $pdf = new Fpdi();
    $pdf->AddPage();
    $pdf->setSourceFile("commentaires.pdf");
    $template = $pdf->importPage(1);
    $pdf->useTemplate($template);
    $pdf->Image('test.jpg', 1, 1, 200, 200);
    $pdf->Output();
?>

Can someone help me please?

Thank you in advance

Faithium
  • 111
  • 1
  • 2
  • 11

1 Answers1

14

Check the namespace on the class. You likely need to include that when instantiating it. Looking at the repo, this should work.

$pdf = new \setasign\Fpdi\Fpdi();
Ryan H
  • 400
  • 2
  • 9
  • @RyanH Thanks this answer will work even if you just installed a package from composer and you did't add anything related this package in "app.php" in laravel – always-a-learner Jan 28 '20 at 05:10