How can we convert the required data in the database into a pdf file, like getting the details of person (when we enter his name) into a downloadable pdf file using java or javascript ?
-
Have a look at iText – Scary Wombat Mar 02 '15 at 07:54
-
How can we make a downloadable PDF file using iText or spdf library files ? @ScaryWombat – Vivek Anoop Mar 02 '15 at 12:01
3 Answers
Assuming you know how to query the DB - creating the PDF can be done using Apache POI, which you can find here: http://poi.apache.org/document/
Here you can see an example of converting XLS to PDF, which is rather similar due to the "cell" nature of both sources: https://stackoverflow.com/a/26056716/1843508

- 1
- 1

- 814
- 7
- 12
-
With respect, I know how to display the output in a PDF file, but what I want to know is how to make it into a downloadable PDF file. – Vivek Anoop Mar 03 '15 at 10:08
-
So why didn't you say so? ;-) Anyway, assuming you are using HTML (or alike) - all you need to do is provide a link to the file you want to make available for download... e.g. Download – Ofer Lando Mar 03 '15 at 11:37
I have used the following to create pdfs using java:
- Jasper Reports
- YaHP
- Building a TeX file and building it.
YaHP was the easiest to use, but I couldn't get it to match my desired output. Building a TeX file yielded the best output but was a nightmare trying to typeset dynamic data. In the end, I settled with Jasper Reports. Jasper Reports connects directly to the database, which may be an advantage for your case.

- 491
- 2
- 8
-
It is not the matter of connectivity to the database, but what I want to know is how to make it into a downloadable PDF file. – Vivek Anoop Mar 03 '15 at 10:26
A (probably simpler) approach would be server-side form filling, using either a library (such as iText, or pdflib), or an application (such as FDFMerge by Appligent, or (if you have a really big purse) products from the LiveCycle family by Adobe).
You'd have to prepare the "template", but for that you have more powerful tools out there than what you can stitch together when creating the PDFs from scratch on the fly (with comparable efforts on your side).

- 3,549
- 2
- 20
- 26