Search code examples
phppdffpdffpdi

Insert images files in existing PDF file using PHP


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.


Solution

  • 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");