I have many PDF forms, I would need to fill them each in php with the data I already have.
Here is just a sample PDF form , I want to fill this form using php. The data I already have in DB. I just want to fill this form and save it.
I am working in PHP Zend Framework.
All I want is when I would download those forms from my site, it would pre-fill all the fields in the pdf form with the information I already have.
Please help me.
I found this and it works for me. It is an unofficial patch for Zend to fill FDF Form Fields.Site with the discussion and patch
NO INSTALLATION, NO OUTSIDE PROGRAMS, NO COORDINATES
Use:
If page no longer exists here is the patch for PDF.php (if someone have problems - write me privete message):
The Zend_Pdf-component can draw text in your pdf, but it is a bit clumsy as you have to specify the x- and y-coordinates on your pdf-page. Something like that:
I don't know if there are easy ways to find the exact coords, I usually play around until it fits.
I found fpdf library looking for the same on internet.
http://www.fpdf.org/en/script/script93.php
Code looks clean, easy to use and remember it, and works for pdf with forms (fillable).
It comes with example that worked out of the box. Hope it helps.
Calling pdftk is a nice way to accomplish this. I'll assume that you know how to execute an external program and leave that out.
First, create an FDF file from your PDF.
You can now use that as template. The sample that you provided looks like this:
The fields are lines that start with
/V ()
. Enter your desired values into those fields. For example:Finally, merge the FDF with the PDF. Execute the command:
If you don't need to keep the FDF and generated PDF files, you can simply pipe the data via stdin and stdout instead of using temp files.
If you don't mind installing Drupal and setting up a simple site, you can install the Fill PDF module and configure it. If you already have the data, then this might be overkill, but if you can import that data into Drupal somehow (like with the Feeds module, for example), then you would save time on writing PDF-filling code. You can use a hosted service with that module or install stuff on your server.
Disclaimer: I maintain that module and run the hosted service.