Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate pdf file and display in a browser

 
vinitha simon
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a J2ee application, in which on the click of a link, a pdf file needs to be generated and displayed on a new tab or window.

Currently, the pdf is generated, but, when written to the output stream, and redirected to the view, the screen just hangs.. I assume there is an exception of some sort which is not being logged for some reason.

I am not sure how to go about debugging this..

Any help is appreciated,

TIA
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without even giving a code snippet, it's tough to debug. It could be, if you are reading to a byte array, the byte array might have been initilized to accomodate more memory.

Try debugging your code in eclipse using breakpoints. You can run your tomcat inside or outside eclipse and then debug.

http://www.ibm.com/developerworks/library/os-ecbug/

 
hayden wangg
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add try{}catch to the top method and log the exception information.
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinitha simon wrote:Hi,
I have a J2ee application, in which on the click of a link, a pdf file needs to be generated and displayed on a new tab or window.

Currently, the pdf is generated, but, when written to the output stream, and redirected to the view, the screen just hangs.. I assume there is an exception of some sort which is not being logged for some reason.

I am not sure how to go about debugging this..

Any help is appreciated,

TIA


Did you set the MIME type correctly? Something like 'application/pdf'
Additionally you can try clearing you browser cache and also redeploy the webapp on the server after cleanly undeploying the app from the server(like removing the web app's folder from work directory in tomcat)
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this will help you..

Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.setPageCount(1);
document.open();
document.add(Add Your Object);
document.close();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");

response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();



Thanks
Amarshi


 
vinitha simon
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the pdf file is not being generated correctly, I did verify the mimetype as well.

But, the java code does not throw any exceptions. Is that normal?
 
Paul Clapham
Sheriff
Pie
Posts: 20949
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's quite normal for Java code to not throw exceptions. It's still possible that your code has bugs, though, even if it doesn't throw an exception. In fact I would guess it's quite likely, since it isn't doing what you want it to do. That's the definition of "bug".
 
vinitha simon
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for the help, I think I'm just going to rewrite my code and try to get it working.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic