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();
%>

