views:

95

answers:

3

I have a PDF which has an image on it (a logo)

I want to open it with PHP and write some text over it and save it back to the file system.

I've done this with the Zend framework before but this project is using code igniter so I need either a standalone lib or a code igniter plugin.

thanks

+2  A: 

Zend_Pdf is a standalone lib.

Zend Framework is deliberately designed with a Use-At-Will architecture, so you can use most components with no (or very little) dependencies on other components in the framework.

To use Zend_PDF in Code Igniter, place the Zend/Pdf folder into your CI project's include path, so it is accessible. Then include it with

// Load Zend_Pdf class 
require_once('Zend/Pdf.php'); 

See this (general) tutorial:

Gordon
A: 

You have FPDF, I used it a while ago it's pretty simple :

http://www.fpdf.org/

With an extension :

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

please google a little bit !

http://www.google.com/search?q=php+pdf&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:official&client=firefox-a

2nd Link

remi bourgarel
TCPDF (http://www.tcpdf.org) is another library you could use.
wimvds
+1  A: 

In my esperience, the first question you should ask is: where the original pdf come from?

Do you want to create the pdf from php, as a template, and then insert the text on it in a second time?

Or you create the pdf in other ways, and then fulfill it via php?

In the first case, go with zend pdf, and write down your class to handle it.

In the second case, you may want to take a look to pdftk, that allow you to merge an fdf file with a PDF file.

Here an example with a forms (and the createFDF.php file), but the behavior can be applyed in many other ways...

Its quite simple:

<?php
require_once('createFDF.php');
$data = array(
    'field_1' => 'Text 1',
    'Field_2' => 'Text 2
);
$FDF_file = 'myfile.fdf';
$PDF_file = 'mypdf.pdf';
$PDF_source = 'your-pdf-original-file.pdf';

$fdf_data = createFDF($PDF_source, $data);
$fh = fopen($FDF_file, 'w');
fwrite($fh, $fdf_data);
fclose($fh);
?>
<h2>File FDF created.</h2>
<?php
passthru("pdftk $PDF_source fill_form $FDF_file output $PDF_file flatten");
?>
<h2>Pdf merged.</h2>

but, you will need to create the original pdf file with forms within by hand (or, as far as i know, there is no tools to create it via php)

DaNieL