iText is basic api to generate pdf from java.
Now, if you are creating a report from db, I hope you must be using servlet/action etc in between where you can generate this pdf.
Also, which reporting api/tool are you using?
As suggested by Shashank, you have to first convert the data into pdf format, then only setting the response type will work.
I tried exporting data as a PDF file from jsp, it worked perfectly for me(I did not use iText, heard about it. Hope while using iText, conevrsion is must but when you set ContentType as PDF in JSP, it automatically take care of the conversion of data. Will learn iText in the coming days.
Your case is slightly different, you already have a pdf file and that is being rendered as pdf. But Aditi's case is different, she is first getting data from underlying database table. So as per my understanding that has to be first converted to a pdf format and then only that can be rendered as pdf.
Your code as this line
So if you render this file to the user with the content type pdf, you should get the correct output. But I don't think that is the case. Probably what you have to do is get the data from table, convert it to pdf using the suggested libraries. Then render that pdf to the user with content type application/pdf.
@Swastik Thanks for the explanation, I understood, why i did not get the error, I tried to export a html table and it did not work, :-). I am looking at iText examples.. As of now i assume that API is converting the data automatically as i do not see any code for conversion. Correct me if i am wrong..
Do you mean that at first it displays a jsp/html with the tabular data, and when the button is clicked it displays the same data in pdf format? If that is the case, you probably need two codes. First one displays the html/jsp page with the button. When button is clicked send to request to server which again invokes a jsp/servlet the generate the pdf contents.
Joined: Feb 23, 2011
yes you are right partially its now opening tabl ein jsp firstly & when i click my pdf file in temp folder in C then it gives th error
Its in the sense still no oopening pdf aqutomatically