Rhys Evans
Rhys Evans

Reputation: 203

Edit PDF files programmatically in PHP

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.

Upvotes: 3

Views: 16625

Answers (3)

Rhys Evans
Rhys Evans

Reputation: 203

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

Upvotes: 2

LiamB
LiamB

Reputation: 18586

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');

Upvotes: 4

Narcissus
Narcissus

Reputation: 3194

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

Upvotes: 0

Related Questions