-2

I have a website that's not ready for production yet. When the user purchase the product it is generating the receipt. What i need to do is i want to give the option to the user to save as pdf. On click of that icon receipt has to be downloaded. I have no idea to do this.

Here is the sample receipt: enter image description here

On Click of this "save as PDF" i need to download this receipt.

Can anyone help me in this.

Priya Sunanthan
  • 441
  • 1
  • 8
  • 18

1 Answers1

3

Your problems can be broken down into following pieces.

When the user clicks "Save as PDF"

  • Generate PDF:

    iText comes very handy in doing this (its free & open source). Here is an example of generating a tabular data in PDF. There are tons of example from iText

  • Download the PDF.

    Once the PDF is generated, the same can be send to the user via response object like any file. Here is an example of downloading a text file. The same can be used for downloading any file.

Hope this helps.

Santosh
  • 17,667
  • 4
  • 54
  • 79