0

I'm using FPDF (plus FPDI).

I have a code like this:

$pdf->setSourceFile("source.pdf");
$tplIdx = $pdf->importPage(1);
$size = $pdf->useTemplate($tplIdx, 1, 1, 5.4);

Result: Works fine.

But when I wrap the code inside a function:

function hello(){
$pdf->setSourceFile("source.pdf");
$tplIdx = $pdf->importPage(1);
$size = $pdf->useTemplate($tplIdx, 1, 1, 5.4);
}
hello();

Result:

Fatal Error: Call to a member function setSourceFile() on a non-object

For some reason, the $pdf object isn't working when inside the function.

Any clue why?

Fomo
  • 143
  • 9

1 Answers1

1

@qrafzvzv, You need to pass pdf object as a parameter inside your function.

For Example :

function hello($pdf) {
    $pdf->setSourceFile("source.pdf");
    $tplIdx = $pdf->importPage(1);
    $size = $pdf->useTemplate($tplIdx, 1, 1, 5.4);
}
hello($pdf);