aspose file tools*
The moose likes JSP and the fly likes Export JSP to PDF format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Export JSP to PDF format" Watch "Export JSP to PDF format" New topic
Author

Export JSP to PDF format

Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
Hello Ranchers..
I'm doing a project in JSP and Oracle..
Here in my project there are two types of department..
Accounts and Sales..
Accounts department is able to download some pages to Excel format and it is working properly..

now in the sales they have to download in pdf format.. then only it is possible to send to the HO..
now what they are doing is downloading the JSP page in excel format and converting to pdf manually using the Acrobat Printer..

is that possible to change to pdf format..

for converting to excel format.. i'm just using 2 lines
and it is here


<%@ page language="java" session="true" import="java.sql.*" import="java.lang.*" contentType="application/vnd.ms-excel" %>
<%
response.setHeader("Content-Disposition","attachment;filename=test.xls");
%>

in the filename side i chaged to test.pdf..
and in the contentType i changed to Acrobat reader
and it is downloading but cannot view the conten..

please help me ranchers.. to solve this problem..

thanks in advance..

regads
Megha Rajeev
Mandar Max
Ranch Hand

Joined: Mar 14, 2006
Posts: 38
The content type should be a valid MIME type. Try setting "application/pdf" as contentType.


"The trouble with doing something right the first time is that nobody appreciates how difficult it was!"
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
Changing content type doesnt change its contents.

You need to create pdf file using third party like iText.
[ May 24, 2006: Message edited by: Dilip Kumar Jain ]

Manesh
Mandar Max
Ranch Hand

Joined: Mar 14, 2006
Posts: 38
I think when Megha says she changed the file name to test.pdf I would assume that the change is being made to the JSP file and there would be a valid pdf file with that name. By common sense, I would not assume that she is renaming test.xls to test.pdf and hoping it to be opened by acrobat reader. But if my assumption is wrong, probably you should consider professional tools for publishing content in pdf.
Megha Rajeevan
Greenhorn

Joined: Mar 22, 2006
Posts: 24
thanks for the reply..
but it is not working properly..

the acrobat reader is opening.. with a message box..

this is the content of the message box
" Adobe Reader couldnot open the file test[1].pdf because it is not either a supported file type or because the file has been damaged.(for example, it was sent and email attachment and wasn't correctly decoded)"

this is the error message i'm getting..
so what to do now..
the page contains table format and all..
i've give the code like this

<%@ page language="java" session="true" import="java.sql.*" import="java.lang.*" contentType="application/pdf" %>
<%
response.setHeader("Content-Disposition","attachment;filename=test.pdf");
%>


please help me for fixing the problem

thanks in advance

regards
Megha
Mandar Max
Ranch Hand

Joined: Mar 14, 2006
Posts: 38
Are you sure that test.pdf is a valid pdf file?
vibhuti vadje
Greenhorn

Joined: May 07, 2014
Posts: 10
Manesh Kumar wrote:Changing content type doesnt change its contents.

You need to create pdf file using third party like iText.
[ May 24, 2006: Message edited by: Dilip Kumar Jain ]


Hi Manesh,
i know we need to use itext for generating a pdf.
But how to use in the same jsp....
What changes we need to make
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
I'll repeat the advice I gave here, where you asked the same question: 1) Don't use JSPs for stuff like this, because it's really bad design. 2) Don't use JSPs for stuff like this, because it is very likely not to work.


Ping & DNS - my free Android networking tools app
vibhuti vadje
Greenhorn

Joined: May 07, 2014
Posts: 10
ok thankss

then how should i do............
can you give me some example
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
Move the Java code to a servlet, and then stream the resulting document to the browser.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Export JSP to PDF format