Help me move data from a database to a PDF, automagically.
June 23, 2006 12:51 PM Subscribe
I need to capture data from an HTML form into a database, then use that data to populate a template. The template, however, is of a certificate of accomplishment, and must be in the form of a printable PDF.
What's a good software/middleware/whateverware package to automatically take the data and inject it into a PDF like this?
More inside.
I'm open to using any OS or database format, none of that has been decided yet. I need to do this quickly and cheaply. I've got the skills for the basic parts, it's the data-to-PDF step that has my stymied. Any help is awesome.
Thanks AskMeFi!
I'm open to using any OS or database format, none of that has been decided yet. I need to do this quickly and cheaply. I've got the skills for the basic parts, it's the data-to-PDF step that has my stymied. Any help is awesome.
Thanks AskMeFi!
Form processing is a cinch with PHP. All the variables from a POST form are stored in an array called $_POST which are referenced like $_POST["first_name"] etc.
You can then use ADOdb to easily connect to a MySQL or other database and populate tables with records from your form data. You can just as easily use mysql_* commands, but in the long run, a little abstraction goes a long way.
Marc Liyanage's build of PHP includes a non-commercial license of PDFLib. The PDFLib component includes commands for generating a PDF file within the web application.
posted by Mr. Six at 1:12 PM on June 23, 2006
You can then use ADOdb to easily connect to a MySQL or other database and populate tables with records from your form data. You can just as easily use mysql_* commands, but in the long run, a little abstraction goes a long way.
Marc Liyanage's build of PHP includes a non-commercial license of PDFLib. The PDFLib component includes commands for generating a PDF file within the web application.
posted by Mr. Six at 1:12 PM on June 23, 2006
PDFs are a combination of ASCII (or Unicode?) text and bitmaps for things like images, fonts, etc. If you have the PDF part already designed, you should be able to replace arbitrary text with data retrieved from an SQL query.
In pseudocode, if you have a template file "foo.pdf" that you want to replace "%placeholder%" with a name from SQL, you might do something like:
posted by revgeorge at 1:14 PM on June 23, 2006
In pseudocode, if you have a template file "foo.pdf" that you want to replace "%placeholder%" with a name from SQL, you might do something like:
$pdf_template = file_read("foo.pdf")
$name = query("SELECT name FROM table WHERE id = $id")
$output = string_replace($pdf_template, "%placeholder%", $name);
file_write("$id.pdf", $output)
posted by revgeorge at 1:14 PM on June 23, 2006
i've used PDFtk to great success, populating application forms. Build the form/certificate in Acrobat with nicely named fields, suck an FDF template out using PDFtk and then use the info from the database to populate your fields in the FDF file. PDFtk merges the FDF into the original PDF template and - viola, populated PDF.
Note that you only need to create the FDF and the PDF once. The only real overhead comes in the pdftk merge step.
posted by casconed at 1:22 PM on June 23, 2006
Note that you only need to create the FDF and the PDF once. The only real overhead comes in the pdftk merge step.
posted by casconed at 1:22 PM on June 23, 2006
I used FPDF some time ago to generate form letters. Pulling data from a MySQL or Oracle database is a piece of cake.
posted by exhilaration at 1:46 PM on June 23, 2006
posted by exhilaration at 1:46 PM on June 23, 2006
Response by poster: You guys rule. I'd been googling all morning, but it was mostly giving me results of database how-tos in PDF format. Soooo meta. Thanks!
posted by mattoly at 2:26 PM on June 23, 2006
posted by mattoly at 2:26 PM on June 23, 2006
exhilaration - i second FPDF as a recommendation. excellent tool, that.
posted by casconed at 3:10 PM on June 23, 2006
posted by casconed at 3:10 PM on June 23, 2006
Definately FPDF + FPDI.
I used PHP with a mysql DB to generate receipts on the fly for a company's POS system.
FPDI lets you load another PDF (as the background), and then use FPDF to write the bits you want onto it.
Read the faq page on FPDF, it has a link to FPDI
posted by mhuie at 4:57 PM on June 23, 2006
I used PHP with a mysql DB to generate receipts on the fly for a company's POS system.
FPDI lets you load another PDF (as the background), and then use FPDF to write the bits you want onto it.
Read the faq page on FPDF, it has a link to FPDI
posted by mhuie at 4:57 PM on June 23, 2006
I use LaTeX, pdf latex and generate tables & other stuff with perl.
Works for me.
posted by singingfish at 9:33 PM on June 23, 2006
Works for me.
posted by singingfish at 9:33 PM on June 23, 2006
This thread is closed to new comments.
However, the project I am currently working on uses FOP to dynamically create PDF's from XMl files, via an XSL Transformation (XSL-FO). This is a web application that uses Java + jsp's to power a complex form.
I did not develop this, I am only maintaining it now. My direct experience has only been updating the XML files when changes need to be made to the pdf's.
I'd suggest doing some searches for these terms if the above links don't help very much.
posted by utsutsu at 1:11 PM on June 23, 2006