1

after doing some research and checking, I feel obliged to ask this question because of the numerous elements at play. Here is how it starts. I have a HTML form that is filled with DOM events, can be changed (altered via javascript), and the last thing the user does is put in their email address and click submit. Upon submit it needs to do the following:

  • convert the html form they just saw (after user selects all the items they want) into a pdf
  • the PDF should not be stored on our server
  • the PDF should be emailed to the email address submitted via the form

I am not expecting anyone to write the code for me on all of this, but some ideas or best ways/tools to accomplish this would be greatly appreciated. The environments are Javascript and PHP.

/-------- Edited --------/ I can use FPDF but did not know if there was a way to use javascript to 'capture' the form they were on just prior to submission of the form that way it does the work for me and I do not have to reproduce the form using numerous lines of FPDF to make it match.

jcsbrotha
  • 89
  • 3
  • 15
  • 4
    This is a pretty straight forward task... use FPDF, store a temp file to email it, then delete it. Not sure what part you're stuck on from the question. – Mattt Jan 11 '13 at 19:28
  • @mjayt well i can definitely look into the FPDF and have read some comments and stuff about it. The storing to a temp file, emailing it, and deleting it is most of what has me stumped then. I am not familiar with how to email a temp file, and how to delete the temp file (am a noob in this arena of PHP) – jcsbrotha Jan 11 '13 at 19:36
  • Well, the temp file should delete itself after the session is destroyed... – crush Jan 11 '13 at 19:40
  • ok thanks @crush... and FPDF does look like it _can_ do the trick, but to reproduce exactly what they had earlier would require a lot of lines on FPDF and I did not know if there was a way to use javascript to capture what the user sees on the form prior to clicking submit and generate a PDF out of that (this would also then make it look exactly as they saw it or close) – jcsbrotha Jan 11 '13 at 19:44
  • Have a look at this on how to generate and email your PDF with FPDF: http://stackoverflow.com/questions/14275172/php-attach-pdf-mail-function/14276551#14276551 – Kaiesh Jan 12 '13 at 01:22
  • [Please follow this link to generate dynamically PDF and send it to mail][1] [1]: http://stackoverflow.com/questions/18396714/how-to-send-email-with-pdf-attachment-using-php/22141096#22141096 – Dheeraj singh Mar 03 '14 at 14:56

2 Answers2

0

TCPDF will also get the job done. I've used it quite a bit for similar tasks. JavaScript can't really communicate to the server to create a PDF file, you'll need to use PHP to do that, so you're going to have to re-create whatever the user sees on the form before submit based on the contents of the form.

This tutorial has the essential steps for submitting a form and attaching the file via email, the only difference is that this tutorial assumes the user is uploading a file as part of the form where-as in your situation you'll be creating the PDF using FPDF or TCPDF instead.

http://www.html-form-guide.com/email-form/php-email-form-attachment.html

stevecomrie
  • 2,423
  • 20
  • 28
0

Try to build your page in a way that allows you to re-create it by using a set of parameters. That way, you can recreate the page again on the server and use a tool like wkhtmltopdf(LGPL) or Amyuni WebkitPDF(freeware, usual disclaimer applies) to generate your PDF file on the fly and send it back to the user.

The workflow will be basically:
1- The user press a "submit" button
2- Your html form makes a request to the server sending all the values collected from the page
3- On the server, you invoke an html-to-pdf tool that receives a url as parameter, with the values that you got from the user included in the url, and you get a PDF as result
4- You send the PDF back to the user as response to his/her request

yms
  • 10,361
  • 3
  • 38
  • 68
  • i do like this idea, but i definitely am shooting for a minimal process, so if there is a way for me to capture it with javascript then send compile that to a PDF and email it, that would be the best – jcsbrotha Jan 11 '13 at 21:10
  • @jcsbrotha I guess that the complexity of the web form that you need to re-create will determine if this approach is the best choice or not. – yms Jan 11 '13 at 21:14
  • yeah, well again I appreciate all of the help! I may wind up going with something like this... and it is doable with this method, but waiting to see if there is something that is lighter and easier that comes around (mostly on the easier part) – jcsbrotha Jan 11 '13 at 22:00