How to export data to pdf?

Help me move data from a database to a PDF, automagically.

  • 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!

  • Answer:

    Some googling came up with a suggestion for http://www.lowagie.com/iText/. However, the project I am currently working on uses http://xmlgraphics.apache.org/fop/ to dynamically create PDF's from XMl files, via an XSL Transformation (http://www.w3schools.com/xslfo/default.asp). 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.

mattoly at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

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 http://adodb.sourceforge.net/ to easily connect to a http://dev.mysql.com/downloads/ or other database and populate tables with records from your form data. You can just as easily use http://us2.php.net/mysql commands, but in the long run, a little abstraction goes a long way. Marc Liyanage's http://www.entropy.ch/software/macosx/php/ includes a non-commercial license of http://www.php.net/manual/en/ref.pdf.php. The PDFLib component includes commands for generating a PDF file within the web application.

Mr. Six

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

revgeorge

i've used http://www.accesspdf.com/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.

casconed

I used http://www.fpdf.org/ some time ago to generate form letters. Pulling data from a MySQL or Oracle database is a piece of cake.

exhilaration

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!

mattoly

exhilaration - i second FPDF as a recommendation. excellent tool, that.

casconed

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 thehttp://www.fpdf.org/ page on FPDF, it has a link to FPDI

mhuie

I use LaTeX, pdf latex and generate tables & other stuff with perl. Works for me.

singingfish

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.