Solved

writting pdf from jsp page

Posted on 2006-06-22
6
443 Views
Last Modified: 2010-04-01
how could i write a pdf from a jsp page and open that pdf in browser...i need sample code for  that. I have tried response.setContentType("application/pdf"); but it not working .may be i am missing someting
0
Comment
Question by:sumana24
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:evnafets
ID: 16964375
Just setting the content type won't magically turn your HTML into a PDF document.
Content type is only an indiciation to the client of what sort of document to expect.

To generate PDF documents, you need to use a library such as IText: http://www.lowagie.com/iText/
JSPs won't help.
0
 

Author Comment

by:sumana24
ID: 16968568
I have used Itext libtary also and follwoed all instructions written over there , only difference is they described the process from generating Pdf from servlet but i used jsp. I was able to create the pdf in ny local drive and render the content in that from jsp but when i am trying to open it in browser by setting content type in response it is not working...it is throwing an acrobad reader error when the respone is coming back and trying to open the pdf
0
 

Author Comment

by:sumana24
ID: 16973904
it is done...ultimately i made it work
0
 
LVL 4

Accepted Solution

by:
evnafets earned 500 total points
ID: 16976986
The problem is that a JSP page is designed to return plain text.
Every carriage return in a JSP file gets put into the output stream.

If you are trying to put a pdf document - or indeed any type of file out via the outputStream, those carriage returns can cause mayhem - corrupting the file.  The safest option is to do it as a Servlet - indeed that is what servlets are for.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unit test DAO layer 1 139
reflection example 3 110
build fail in maven project 11 188
struts hibernate integration example 28 140
This article describes how to reset your Windows 10 password when you've forgotten it.
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question