Insert images files in existing PDF file using PHP

125369 picture 125369 · Mar 6, 2012 · Viewed 23.8k times · Source

My need is that I upload two image files and that should be added to an existing PDF file. I have read about FPDF, basing on that I have followed this post link. In case if somebody can post a simple working example/link it would be helpful for searchers like me and some more people who would also take the same route to find some helpful answers.

Answer

tonymarschall picture tonymarschall · Mar 6, 2012

It seems there is an extension called FPDI for FPDF. Here is a blog post about how to modify an existing pdf: http://pranavom.wordpress.com/2011/03/15/modify-pdf-using-fpdffpdi-library/

You can place an image using FPDI like so:

$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile("MySource");
$template = $pdf->importPage(1);
$pdf->useTemplate($template);
$pdf->Image('MyImage.jpg', $x, $y, $width, $height);
$pdf->Output($outputPath, "F");