0

I have a template located at "public/form/file.pdf" and what to get the page height and the page width but I'm encountering error "Call to undefined method setasign\Fpdi\Fpdi::GetPageWidth()"

I installed via composer of the following packages:

"setasign/fpdf": "1.8",
"setasign/fpdi": "^2.3"

Controller

$pdf = new Fpdi();
$page_count = $pdf->setSourceFile(public_path()."/form/file.pdf");
$w = $pdf->GetPageWidth();  // Width of Current Page
$h = $pdf->GetPageHeight(); // Height of Current Page
dd($w);

Question: How do I get the width and height of current page?

Angel
  • 966
  • 4
  • 25
  • 60

2 Answers2

0

Are you sure that you receive this error? I mean the called methods are standard methods of FPDF. You can get the size of an imported page like this:

$tplId = $pdf->importPage(1);
$size = $pdf->getImportedPageSize($tplId);

echo $size['width'];
echo $size['height'];
echo $size['orientation'];

For details see here.

Jan Slabon
  • 4,736
  • 2
  • 14
  • 29
0

You must create a page before you can access it's dimensions.

$pdf = new Fpdi();
$pdf->setSourceFile($file);

$templateId = $pdf->importPage(1);
$size = $pdf->getTemplateSize($templateId);

$pdf->AddPage($size['orientation'], $size);
$pdf->useTemplate($templateId);

$w = $pdf->GetPageWidth();
$h = $pdf->GetPageHeight();

See the following example from the documentation as reference: https://manuals.setasign.com/fpdi-manual/v2/the-fpdi-class/examples/#index-3

Sergej Tihonov
  • 221
  • 1
  • 5