how to export pdf using jsp

hai friends

i know to export excel using jsp

but tried the same process to pdf, it s not work..

please give some solution......

thanks

rex

[176 byte] By [kingofpeacea] at [2007-11-27 10:27:57]
# 1

What is the problem exactly? The principle behind it is the same....

nogoodatcodinga at 2007-7-28 17:48:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

response.setContentType("application/pdf");

response.setHeader("Content-Disposition","attachment;filename=sample.pdf);

i wrote this code, but its not working.

can u give the code for export pdf.........

kingofpeacea at 2007-7-28 17:48:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> response.setContentType("application/pdf");

This seems to be fine.

> response.setHeader("Content-Disposition","attachment;f

> ilename=sample.pdf);

I'm not sure about this but shouldn't it be something like this?

resp.setHeader("Content-Disposition","attachment; filename=\"sample.pdf\"" );

I'm not sure if the quotes are necessary....

And you are opening and writing the contents to the output stream right?

Also, you still haven't mentioned, how exactly is it "not working"? Do you get the wrong output? Empty file? No file?

I'll just give this a try and get back to you

nogoodatcodinga at 2007-7-28 17:48:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

hai friend

i tried this , its created a pdf file, but content not display..........there is a problem in opening a content...

so please tell some other method to get a pdf file................

kingofpeacea at 2007-7-28 17:48:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Is the content length set in the header?

You may find useful information in this topic: http://forum.java.sun.com/thread.jspa?threadID=5194486

BalusCa at 2007-7-28 17:48:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

It's working absolutely fine for me. I suspect the problem is one of these two:

1. You're giving the incorrect path of the file. Check the size of the downloaded file, it's probably 0 bytes.

2. Check the file that has been created on the server first; is that fine? That could also be the origin of the problem.

This is th code I've used. I copied an existing PDF to my webapps root folder ( $CATALINA_HOME/webapps/myApp/test.pdf ) and hardcoded the values of filename to check it and it works for me.

BufferedOutputStream out = new BufferedOutputStream( resp.getOutputStream());

try

{

filename = "test.pdf";

resp.setContentType("application/pdf");//vnd.ms-excel" );

resp.setHeader("Content-disposition","attachment; filename=\"" + filename + "\"" );

BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("/") + filename));

int i;

while ((i=bufferedInputStream.read()) != -1)

{

out.write(i);

}

bufferedInputStream.close();

out.flush();

out.close();

}

catch ( Exception e )

{

System.out.println(e);

}

nogoodatcodinga at 2007-7-28 17:48:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...