views:

262

answers:

3

Hey background info: 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".

ive seen links to fpdf/pdfi/dompdf etc but cant find any useful example code that i could use :s any help / pointers would be greatly appreciated.

+3  A: 

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');
Pino
I've tried that.. cant seem to get it working :| got an example you could post?
Aceth
Updated main post
Pino
Am i meant to be getting deprecated errors with the latest download of fpdi?" Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\csllive\fpdi.php on line 88"
Aceth
also do i use the php str_replace to replace the text or is there some function in fpdi?
Aceth
A: 

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 :)

Narcissus
was ideally looking for an opensource/free lib/class
Aceth
A: 

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

Aceth