Title: JSP, PDF, taglibs
Fredrik,
 
Here is the contents of my JSP so far...
 
<%
response.setContentType("application/pdf");
java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
com.lowagie.text.Document document = new com.lowagie.text.Document();
com.lowagie.text.pdf.PdfWriter writer = com.lowagie.text.pdf.PdfWriter.getInstance( document, buffer );
document.open();
document.add(new com.lowagie.text.Paragraph("Hello World"));
document.close();
byte[] bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
for(int i = 0; i < bytes.length; i++)
{
    out.write(bytes[i]);
}
%>
 
Although when I write out to the screen, all I get is....
 
%PDF-1.4 %???? 3 0 obj <> stream x?+?r ?26S?00SI?2P?5?1??  ?B??4> /ProcSet [/PDF /Text] >> /Parent 1 0 R /MediaBox [0 0 595 842] /Contents 3 0 R /Type /Page >> endobj 2 0 obj <> endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj xref 0 7 0000000000 65535 f 0000000386 00000 n 0000000290 00000 n 0000000015 00000 n 0000000145 00000 n 0000000442 00000 n 0000000490 00000 n trailer <> startxref 600 %%EOF
 
I have to use the "out" because for some reason when I forward to my JSP from a servlet, if I then try to call response.getOutputStream() is throws an Illegal State Exception saying that the getWriter has already been called. (I am using JBoss 3.0.2/Tomcat 4.0.4)  Is there any way that I use the write method to display the file? Have you had any luck with that?  I mean, another way would be to prompt the user to download the file to their computer, but then again, I had no luck with that as well.  Anyways, thanks in advance.
 
Daniel
-----Original Message-----
From: Fredrik Nilsson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:59 PM
To: [EMAIL PROTECTED]
Subject: Re: [iText-questions] JSP, PDF, taglibs

 Hi Daniel,
 
It is pretty straight forward as in the java code.
 
One thing to be careful about is that you cannot have any newlines ("enters") outside of the jsp-tags.
(I.e. the import page in the beginning of the jsp-file must be on the same row)
 
Regards,
Fredrik
 
----- Original Message -----
Sent: Friday, December 27, 2002 12:01 AM
Subject: [iText-questions] JSP, PDF, taglibs

Hi,

I am trying to use iText with taglibs and am wondering if anyone has ever played with that before.  I basically want to have iText created a PDF document using taglibs from a JSP page, and then just write the document to the browser and let the browser deal with opening/downloading it, etc.  I am wondering if anyone has ever done something like this before?  The context in which this would be used is that a Servlet would forward a request to the JSP, and the JSP would create a PDF using JSP tags based upon the information in the request.  Thanks in advance for any help provided.

Daniel

Reply via email to