Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andyandy's avatar

FPDF sizing of the image - anybody knows how to?

I want to take JPG image and convert it to PDF. There are two scenarios:

  1. take single JPG, fill 100% of the width of the PDF
  2. take 2 images, size them to 297mm x 100mm (=half of A4), place them on the same page

I have this code using FPDF.

$pdf = new FPDF();
$pdf->setPrintHeader(false);
$pdf->AddPage();
$img_link = 'http://www.......';

$pdf->Image($link, 0, 0, 0,0);

$pdf->Output($_SERVER['DOCUMENT_ROOT'] . 'public/upload/test.pdf', "F");

I can find manual and even examples. http://www.fpdf.org/en/doc/image.htm But I have absolutely no idea what are they trying to say by that or how any of these units are suppose to work. I woukld be very grateful for the help with this.

0 likes
4 replies
Tray2's avatar

It doesn't look that tricky.

$pdf->Image(<imagefile>,<x-cordinate>, <y-cordinate>,<width in pixels>);
$pdf->Image(<imagefile>,<x-cordinate>, <y-cordinate>,<width in pixels>);

So something like

$pdf->Image('image1.jpg', 10, 10, 200);
$pdf->Image('images2.jpg', 220, 10, 200);

Should probably work.

andyandy's avatar

If anybody finds this thread later, set all this stuff before setting image size:

                $pdf->setPrintHeader(false);
                $pdf->SetPrintFooter(false);
                $pdf->SetMargins(0, 0, 0);
                $pdf->SetAutoPageBreak(false, 0);
Tray2's avatar

If your problem is solved please mark the reply that helped you solve it as best.

Please or to participate in this conversation.