<servlet-name>GeneratePDF</servlet-name>
<servlet-class>"Your package"/GeneratePDF</servlet-class>
</servlet>
<servlet-name>GeneratePDF</servlet-name>
<url-pattern>../GeneratePDF.jsp</url-pattern>
</servlet-mapping>
From: [EMAIL PROTECTED] on behalf of Aaron Wallace
Sent: Thu 1/13/2005 3:28 AM
To: [email protected]
Cc: Brian Burridge
Subject: RE: [iText-questions] PDF Generated is Blank
This is harder to do than it should probably be, mainly because
the JSP
will consistently try to send bits of whitespace (i.e. from between
the
JSP tags) to the JSP's output writer, no matter how carefully you try
to
eliminate any whitespace from between the JSP tags, while you want
to
send binary data directly to the servlet's output stream.
This
should work with Jasper-based JSP
engines:
...
<%
response.reset();
response.setContentType("application/pdf");
response.setHeader("Content-disposition",
"filename=foobar.pdf");
// send PDF using response.getOutputStream() as
the output stream; i.e.
// PdfWriter.getInstance(...,
response.getOutputStream());
response.flushBuffer();
%>
...
JSP
buffering should be enabled so that the call to response.reset()
will prevent
any stray text/whitespace generated before this call from
being sent to the
browser.
While the above will work, you will probably get errors
because, after
the flushBuffer() call, the JSP will try to send mote
text/whitespace
via the output writer, which isn't allowed once binary data
has been
sent. A quick hack workaround is to create a subclass
of
(javax.servlet.jsp.)JspWriter in which all of its (many) methods
discard
their data, then assign it to 'out' after the flushBuffer call
above:
out = new NullJspWriter();
The above hack may not be
necessary--in my experience, the PDF is
correctly sent to the client and the
errors, while annoying, are
harmless.
> -----Original
Message-----
> From: Brian Burridge [mailto:[EMAIL PROTECTED]]
>
Sent: Tuesday, January 11, 2005 8:22 AM
> To: iText
> Subject: Re:
[iText-questions] PDF Generated is Blank
>
> I'm using Tomcat for
the JSPs. I would really rather use
> JSPs, because I'm supposed to be
integrating iText into an
> existing website without changing the
architecture, and they
> use JSPs for everything. They have tag libraries
that do all
> the data iteration and I was hoping to reuse those as
well.
>
> Can you give any direction as to how to tell Tomcat to
serve
> a JSP as
binary?
-------------------------------------------------------
The
SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited
edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well,
almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
iText-questions
mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
