Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit PDF files programmatically in PHP

Tags:

php

pdf

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.

like image 935
Rhys Evans Avatar asked Jun 19 '26 08:06

Rhys Evans


2 Answers

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');
like image 161
LiamB Avatar answered Jun 20 '26 22:06

LiamB


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

like image 36
Rhys Evans Avatar answered Jun 20 '26 21:06

Rhys Evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!