Convert byte Stream to jsp and display it as part of jsp

Hi all,

I have a very peculiar requirement. I have to create pdf s at runtime from byte stream from input and display it as part of a jsp which has already some information displayed.

I have searched a lot for this but not able to come up with a suitable solution. Please help me in this as this is a very important deliverable for me...

First i tried creating pdf's on the runtime using iText and displayin but even that there are problems .Pls help me out

When this jsp is executed is says the file is corrupeted and could not open hence...

Here is the code i used :

%@page import="java.io.*, com.lowagie.text.*, com.lowagie.text.pdf.*,javax.servlet.*"%>

<%String msg= "Lightning flashed across the sky. Thunder rumbled in the distance. " + "The wind began to moan, as if in pain. The good people of the village " + "huddled together in the common room. Fear glistened in their eyes and " + "their hearts pounded with terror. Evil was descending into their " + "valley, and there was nothing they could do to save their lives ...";

ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();

Paragraph para= new Paragraph(msg);

Document document = new Document();

response.setContentLength(baosPDF.size());

response.setContentType( "application/pdf" );

response.setHeader("Content-disposition","attachment; filename=foobar.pdf" );

PdfWriter docWriter = null;

docWriter = PdfWriter.getInstance(document, baosPDF);

document.open();

document.add(para);

document.close();

docWriter.close();

ServletOutputStream sos = response.getOutputStream();

baosPDF.writeTo(sos);

sos.flush();

out.clear();

out=pageContext.pushBody();

%>

[1791 byte] By [vshankar1985a] at [2007-11-27 8:09:59]
# 1

> I have a very peculiar requirement. I have to create

> pdf s at runtime from byte stream from input and

> display it as part of a jsp which has already some

> information displayed.

Peculiar, yes. Stupid too because it can't be done. You can produce an HTML document or you can produce a PDF document, but you can't produce a mixture of the two.

DrClapa at 2007-7-12 19:53:19 > top of Java-index,Java Essentials,Java Programming...
# 2
are u sure cause it is a major requirement of my project. Pls confirm as I have to give a requirement analysis for this. Is there no other way to do this.. Kindly help . I am doin this project in struts . Is there any possibility to achieve this is struts framework.
vshankar1985a at 2007-7-12 19:53:19 > top of Java-index,Java Essentials,Java Programming...
# 3
> are u sure Yes.You can produce HTMLYou can produce a PDFBut it is impossible to do both at the same time.Impossible. Struts or no Struts. Requirement or not. It does not matter. It is impossible. Period. End of story.
cotton.ma at 2007-7-12 19:53:19 > top of Java-index,Java Essentials,Java Programming...