5

Tricky question.

I have a very long form where the user writes down a lot of data. I need to save the form for future reading (pdf, html, or even a jpg will do), but I need to save it with the data that the user wrote down. This has to be done on submitting the form.

I know it's going to be impossible with only PHP, but would it be possible with a little help from javascript-ajax?

I can't prompt the user to print the page, and I need to save the view without any other input from the user (beside the submit).

Any ideas?

EDIT:

in a nutshell,

is it possible to generate a pdf from that page without submitting the data ? is there a way fpdf (or others) could "read" and save what's currently on the screen, just like a "print" function ?

imagine a long, looong form, with a button "save as pdf" who saves the current page (with the data inputted from the user) WITHOUT submitting the form....

NicolaPasqui
  • 1,112
  • 8
  • 17
  • http://stackoverflow.com/questions/1648715/best-pdf-generator-in-php-mpdf-or-fpdf something to read while you wait for other comments. – phill Feb 03 '11 at 16:56

3 Answers3

1

You can have a look at: http://php.net/manual/en/book.pdf.php and this http://www.tcpdf.org/

Hope this helps you.. Thanks

Chetan Sharma
  • 2,539
  • 5
  • 25
  • 41
1

Take a look at the thread: Which is the best PDF library for PHP?

Highested listed solutions include:

Another possible solution would be converting HTML to PDF in PHP: HTML to PDF in PHP

Community
  • 1
  • 1
calvinf
  • 3,754
  • 3
  • 28
  • 41
  • thanks ! (i'm already using fpdf). what i need is to generate the pdf ON submitting the form (not using the posted data) with all the inputs from the user...is there a way i cand do it (maybe with an ajax call ) ? – NicolaPasqui Feb 04 '11 at 08:14
  • Submit the form information using Ajax to a PDF generating PHP file, save the PDF somewhere, and then do what you need with it. That's definitely possible. If that's not what you're looking for, you should update your question and provide more info about the use case. – calvinf Feb 04 '11 at 19:19
  • yeah that's the way to go, but is it possible to generate the pdf without submitting the data ? is there a way fpdf (or others) could "read" and save what's currently on the screen, just like a "print" function ? – NicolaPasqui Feb 07 '11 at 08:12
  • No, you have to submit the data somewhere to generate the PDF. AFAIK, there's not client side tools that support generation of PDFs. – calvinf Feb 08 '11 at 21:58
0

If you want to go from form data to PDF then one of the methods you could try is to take the submitted data, create a HTML document, and convert that document to PDF. You wouldn't necessarily need to send the HTML to the user (though you could) because you'd be using the HTML merely for formatting purposes. Push the HTML into a variable and then parse it through one of the many HTML to PDF converters.

hawbsl
  • 15,313
  • 25
  • 73
  • 114
BrianS
  • 13,284
  • 15
  • 62
  • 125
  • yeah, but what i need is a pdf print of the data BEFORE the submit...kind of a "print before submit" function... – NicolaPasqui Feb 04 '11 at 08:07
  • Are you saying you need to process the data locally on the user's machine before it is submitted? What about processing the data on the server and producing the PDF at the same time? – BrianS Feb 04 '11 at 17:47