Adding images over PDF using FPDI and TCPDF

Wojtek Grabczak picture Wojtek Grabczak · Apr 29, 2015 · Viewed 9k times · Source

I'm trying to add images on top of an existing PDF.

The pdf contains a blank grid, I am writing a script that will insert images on top of the PDF and output a new modified PDF file.

I am using FPDI and TCPDF libraries to load and edit the PDF file.

Any image or text i try to add using Write(); and Image(); functions does not appear anywhere in the Output file.

Answer

Jan Slabon picture Jan Slabon · Apr 30, 2015

This script works without problems! Expecting that all resources are accessible. The MultiCell call looks something special but as you'd used single quotes at least the string $pdf will appear in the resulting document. Furthermore the header() is obsolete too. Make sure that your PHP file is saved without a BOM to get rid of the ob_clean() call, too.

Generally it should be a good practice to define a font and size before writing any text but it seems that TCPDF handles this internally by a standard font for you.

Also make sure that you are using the latest version of both FPDI and TCPDF.