tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fred Toth <>
Subject Byte-serving PDFs unsupported? Or broken?
Date Sun, 14 Sep 2008 17:24:18 GMT
Hi all,

I've been trying to get to the bottom of an old question:

Does tomcat support byte-serving of PDF files? In searching the archives,
this comes up every few years or so and most responses are confusing
and inconclusive.

Here's more detail on the question, starting with my symptoms:

For unrelated reasons, I just switched a client's site from using apache 
to using tomcat 5.
I immediately starting hearing "PDFs are slower to download". I was able 
to confirm
this. For example, a 14mb PDF on my connection using tomcat takes about 
45 seconds before
the first page appears in the browser. On a generic apache install, I 
see the first page
in approximately 1 second.

The reason for this is that tomcat, out of the box, does not appear to 
support "byte serving",
or, possibly, it doesn't support it in a form that's acceptable to Adobe 
browser plug-ins.

To understand this one needs a bit of info on PDF internals:

It is possible to create PDFs that are "optimized for web view". PDFs in 
this form are
rearranged internally such that the first page can be delivered more 
quickly. (Earlier PDFs
kept all pointer information at the end of the file, which meant the 
entire file had to
be downloaded before the reader could find the first page.)

The apache web server supports these "optimized" PDFs with no particular 
However, tomcat does not.

What I can't seem to find out is if this is just not supported? Or does 
it require some
specific tomcat configuration? Or does the Acrobat plug-in bend the 
in a way that apache handles, but tomcat does not?

The underlying technology is based on particular HTTP headers. 
"Accept-Ranges" is used
by the server to say, "Yes, you can ask me for byte ranges of a file". 
The browser (or, in
this case, the Acrobat plug-in) responds with specific Content-Range 
requests, essentially treating
the PDF file as a random-access file.

I'm amazed that this doesn't come up more often, considering the 
prevalence of PDFs
(and the prevalence of tomcat!)

Also, here are some common discussion comments that are NOT the answer 
I'm seeking:

1. Yes, tomcat serves PDFs out of the box quite nicely.
2. Yes, one can use apache to serve PDFs instead of tomcat. This is not 
an option
in my case because I'm using tomcat to implement access control to those 
3. Yes, I know that one could write code to solve this, but I'm hoping 
that DefaultServlet
can do this. It's not trivial to implement.
4. I've seen comments that indicate that there is general support in 
tomcat for Accept-Ranges
and Content-Range. But I've also seen indications that Acrobat might 
require some specific
flow of headers before it does the right thing. I can confirm that 
neither tomcat 5 nor tomcat 6
handle this properly (at least with a generic configuration).
5. Yes, 14mb is quite large for a PDF and there are ways to make smaller 
PDFs. This particular
client has specific reasons for using such large PDFs.
6. This has nothing to do with generating PDFs on the fly. These are PDF 
files sitting
quietly in the web root.

Thanks for any advice you might have!

Fred Toth

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message