• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to print PDF from JSP?

 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I am getting byte[] of PDF Report using JasperReport.

How can I print it using JSP?

Reg,
Chetan
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Print API will help. Have a look on Sun's site for it - there's a tutorial etc. there.

Of course, since this is a JSP it will print it serverside. Is that what you want?
[ November 16, 2004: Message edited by: Paul Sturrock ]
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actully I am priting pdf in a iframe using follwoing code

...

response.setContentType("application/pdf");
out.print(pdfByteArray[]);

....

But it is not working

I just want to print byte[] in using JSP as PDF.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the API docs (sigh...).

out is a PrintWriter, a PrintWriter works only with plain text.

What you need is a binary outputstream which you just happen to have available in the servletresponse.
Retrieve it using response.getOutputStream() after which you can . And use write(byte[]) and not the print() functions as those will assume you're writing text.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is a spectacularly poor technology choice for this. Do yourself a favor and do it with a servlet.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I will try to use Servlet.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tried following code in JSP only and it is working fine.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!