Tutorial :Edit PDF files programmatically in PHP



Question:

Background info: I got a project to produce a customised PDF on the fly from a given PDF file using PHP. All I need it to do is to replace strings, e.g. search in "template.pdf" for "{Address}", replace with "Street Name".

I've seen links to fpdf/pdfi/dompdf etc., but can't find any useful example code that I could use :s. Any help / pointers would be greatly appreciated.


Solution:1

fpdf is fantastic, you need to use somthing else to import an exisitng PDF though, See below.

http://www.setasign.de/products/pdf-php-solutions/fpdi/

require_once('fpdf.php');  require_once('fpdi.php');    $pdf =& new FPDI();    $pagecount = $pdf->setSourceFile('TestDoc.pdf');  $tplidx = $pdf->importPage(1, '/MediaBox');    $pdf->addPage();  $pdf->useTemplate($tplidx, 10, 10, 90);    $pdf->Output('newpdf.pdf', 'D');  


Solution:2

decided to generate html web page (PHP) then use wkhtmltopdf (http://code.google.com/p/wkhtmltopdf)

to produce the pdf bit of a work around but less hastle


Solution:3

PDFlib (with the additional PDI) from pdflib.com should be able to do this for you. Admittedly it is pretty pricey, so there may be other options, too :)


Solution:4

You may use FPDF or TCPDF Library classes to do so. With these classes, you can quickly, easily and effectively generate/edit PDF files.

Have a look at this article which informs about these two libraries: Easily create PDF files on the fly with PHP


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »