You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Mazza, Glen R, PERSCOM" <Gl...@hoffman.army.mil> on 2002/08/21 20:38:56 UTC

setContentLength() function for PDFs

Hello,

How important is calling "response.setContentLength()" prior to returning a
PDF to the client?

I would like to create a function that will take an outputStream, generate a
PDF document and write to that stream, and then close the stream.  I'd like
the function to be generic for files (FileOutputStream) or servlets
(ServletOutputStream).

The only problem I can see with this is that "normally" you need to set the
content length before sending out to a servlet:

sendPDFDocument(OutputStream out)
{
	ByteArrayOutputStream baos = ....
...
	byte[] content = baos.toByteArray();
//	response.setContentLength(content.length);
	out.write(content);
	out.flush();
	out.close();
}

But the code *will* send out to the client correctly without
"setContentLength" being called, so maybe setContentLength() is not that
important.

[If I have to call setContentLength(), I think I'll just return the
ByteArrayOutputStream to the servlet for it to make the call.]

Thanks,
Glen

Re: setContentLength() function for PDFs

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Mazza, Glen R, PERSCOM wrote:
> How important is calling "response.setContentLength()" prior to returning a
> PDF to the client?

IEx at least up to 5.5 will be confused and won't display
the PDF at all if the content length was not set. I don't
know what happens with IEx 6.

In any case, users will get an informative progress meter
if the content length has been set, with ETA for download
and all, and they wont get it if the length was not set.

J.Pietschmann