I would like to be able to write / overlay text on top of an existing pdf document using PHP. I hope you have a pdf document that can act as a template and fill in the blanks by opening the template document, overlaying the appropriate text and showing the result as a new document. A template document is a single page, so page merging / manipulation is not required.
Are there any free libraries that can do this? Wherever I look? Most of my queries seem to be related to document merging / adding pages, instead of overlaying content on top of an existing page.
Thank.
* EDIT: Here's what I did: 1. Download FPDF 2. Download FPDI + FPDF_TPL from
http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/
Here is a sample code for any future wanderers (adapted from samples at www.setasign.de):
<?php include('fpdf.php'); include('fpdi.php'); // initiate FPDI $pdf =& new FPDI(); // add a page $pdf->AddPage(); // set the sourcefile $pdf->setSourceFile('templatedoc.pdf'); // import page 1 $tplIdx = $pdf->importPage(1); // use the imported page as the template $pdf->useTemplate($tplIdx, 0, 0); // now write some text above the imported page $pdf->SetFont('Arial'); $pdf->SetTextColor(255,0,0); $pdf->SetXY(25, 25); $pdf->Write(0, "This is just a simple text"); $pdf->Output('newpdf.pdf', 'D'); ?>
php pdf
filip-fku Nov 28 '10 at 21:53 2010-11-28 21:53
source share