Search code examples
fpdffpdi

Class 'FpdfTpl' not found but required / included


So I am very confused.. The paths for the requires below are correct. Been working in Java on Android and haven't been in PHP for awhile but I have done a lot in PHP and never had this issue.

Autoload should be loading everything according to the docs for FDPI. What the hell am I missing here.

require_once('fpdf/fpdf.php');
require_once('fpdi/src/autoload.php');

$pdf = new FpdfTpl();
$pdf->AddPage();

$templateId = $pdf->beginTemplate();
$pdf->setFont('Helvetica');
$pdf->Text(10, 10, 'HEADING');
$pdf->endTemplate();

$pdf->useTemplate($templateId);

for ($i = 9; $i > 0; $i--) {
    $pdf->AddPage();
    $pdf->useTemplate($templateId);
}

$pdf->Output();

Solution

  • You simply missed the namespace:

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

    or at the top of the file:

    use setasign\Fpdi\FpdfTpl;