How do I output HTML form data to PDF?

I need to collect data from a visitor in an HTML form and then have them print a document with the appropriate fields pre-populated. They'll need to have a couple of signatures on the document, so it has to be printed. The paper form already exists, so one idea was to scan it in, with nothing filled out, as an image. I would then have the HTML form data print out using CSS for positioning and using the blank scanned form as a background image. A better option, I would think, would be to automatically generate the PDF with this data, but I'm not sure how to accomplish either. Suggestions and ideas would be greatly appreciated! =)

asked Feb 22, 2012 at 21:37 285 1 1 gold badge 2 2 silver badges 8 8 bronze badges

4 Answers 4

I would have to respectfully disagree with Osvaldo. Using CSS to align on a printed document would take ages to do efficiently in the aspect of cross-browser integration. Plus, if Microsoft comes out with a new browser, you're going to have to constantly update for the new use in browsers.

If you know any PHP (Which, if you know JavaScript and HTML, basic PHP is very simple), here's a good library you can use, FDPF:

Thankfully, PHP doesn't deprecate a whole lot of methods and the total code is less than 10 lines if you have to go in and change things around.

answered Feb 23, 2012 at 4:46 Christopher Christopher 267 5 5 silver badges 19 19 bronze badges

I went to: html2fpdf.sourceforge.net and this is what I read on that page: "Warning: This page requires Adobe Acrobat Reader plugin installed. Go THERE if you don't have one." The THERE link takes me to Adobe, but I do have Acrobat Reader installed. If you use PDF embed on a page, be sure it doesn't provide better cross-browser integration than an html+css page.

Commented Feb 23, 2012 at 23:14

I'm not sure I understand your comment fully. It sounds like the THERE link is only for people who don't have Adobe Acrobat on their computer. And of course, if you're working with PDF you would definitely need to have Acrobat installed.

Commented Feb 24, 2012 at 5:48

I do have Acrobat Reader installed and I do saw the warning message above, on that page, instead of the PDF some other people are seeing.

Commented Feb 24, 2012 at 16:00

I side with @Christopher on this one. I know this post is old, but there's a great script here that utilizes the FPDF library.