File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp to pdf

 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey i am designing some web pages in jsp

now when i input certain information reports are being created from database

now i want those reports to be in pdf format

what should i do

please guide me
thank you
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably setting the response type to application/pdf should solve the problem.
 
Shashank Ag
Ranch Hand
Posts: 88
Java Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

If none, try iReports its free and very easy.
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hope this helps, If you need more help ,please let us know.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys for your help

@deepak

where should i include this code & i dnt already have any pdf file i have to show my jsp page report in pdf format

please help me

thank you
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey when i give this code then i got an error opening the document

file doesnot begin with %pdf
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditi,

As suggested by Shashank, you have to first convert the data into pdf format, then only setting the response type will work.
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditi agarwal wrote:hey when i give this code then i got an error opening the document

file doesnot begin with %pdf


Can you please post what you have tried?
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Aditi,

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.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sory bear for using java class code in jsp

hey thanks both of you for replying

i am giving same as you have written deepak


@swastik i cannt understand how to do that

thank you

 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Deepakkumar

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.

Aditi

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.

 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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..

Aditi

The link is for you, hope it will help.

java]http://www.coderanch.com/how-to/java/ItextExample
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply @swastik & @deepak

but still it cannot include

com.itextpdf.text.*,com.itextpdf.text.pdf.*

files
what could be the problem
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have not add the Itext jar path to your class path.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@deepak thanks for your reply

i have already added itext-1.3.1 .jar but still its giving error if you have any link for itext then please post it so that i can download it from new link

if any other problem is there then please let me know

thank you
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@swastik thanks for reply but that link is not working
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its working for me even now. I just tested it. It opens and pop ups a window to save the jar file. If you wish I can send the file.
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That link works, May be your browser blocks you downloading the file. If so,just click the message that gets displayed at the top of the page and select download file.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@swastik then please send me that file bcause i need that if still it will make any error then i can discuss it here only

thank you
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to disappoint you both guys but still same error is coming

that is

there was an error opening this documentfile doesnot begin with %PDF

 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, the import issue is resolved. Could you please show your code?
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure this is my code




 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Comment/Remove the following two lines


And make sure in c:\ (c root) you have a folder called temp, because the code is create the file FirstPdf.pdf under temp folder which is under c:\.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem is solved to some extent but still hard luck

actually i need that link as soon as clicked it should open file in pdf format not jsp as it is doing now

& the firstPdf.pdf which is gettings aved in temp when clicked shows

"there was an error opening this document sharing violation"



thank you
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

thank you
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know sharing violation is a os level issue, as you are trying to open the file manually. Just stop tomcat or whatever server you are using and see if it opens.
 
Aditi agarwal
Ranch Hand
Posts: 225
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks swastik its now not showing violation error but showing file load error
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditi

Your code is not writing anything to the pdf file, that might be a probable reason. Just after opening the document, write something to the file



It would be also good, if you declare the document object before starting try block and close it in finally block.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic