Jump to content

Apache2 / PDF problem [solved]


xxbeanxx
 Share

Recommended Posts

Does anyone know how I can fix this problem...? It seems to be a caching issue with Internet Explorer 5+.

 

What happens is, the first time a user clicks on a PDF, it loads fine, but any subsequent clicks results in "file does not start with %PDF" error.

 

Looking in IE's cache, I find the PDF, and upon opening it in notepad, I find it's all corrupted. I've done google searches and cannot find anything that gives me an idea about how to fix this. I've tried every solution out there, but to no avail.

 

Please someone help me!! This is causing me a lot of grief...many many phonecalls.

 

I'm using the latest apache, php distributed in MDK 10.1 updates.

Link to comment
Share on other sites

Is the URL in their browser whatever.pdf or does it end with *.php?

I encountered this IE evillness on my website. One of the workarounds I found was to create a fictitious variable, if that's the case.

http://THIS-IS-JUST-AN-EXAMPLE.com/mypdf.php?extension=.pdf

 

and that tricks IE and its helpers.

Link to comment
Share on other sites

Is the URL in their browser whatever.pdf or does it end with *.php?

I encountered this IE evillness on my website. One of the workarounds I found was to create a fictitious variable, if that's the case.

http://THIS-IS-JUST-AN-EXAMPLE.com/mypdf.php?extension=.pdf

 

and that tricks IE and its helpers.

 

 

Thanks for the reply. I don't think this is the problem, however. For example, if I open the temporary internet files on the box with IE, the file shows as whatever.pdf.

 

One thing I've noticed though is whever a user clicks on the pdf the first time, it works okay. Subsequent times apache2 returns a 304, which is basically telling the IE box to load the cached version.

 

If I open the cached version in notepad, I see a bunch of chunks in arbitrary order. I mean, the end of the file may be at the beginning, while the middle could be at the end...etc. However, the very first chunk is never present. I dunno if this makes sense to you...but if I were to take each piece and put them in the correct order, I would get an almost complete PDF.

 

Anyhow, I've tried making apache rewrite headers so that it tells IE not to cache the files, but it seems like IE never listens. It is quite annoying.

 

I know that chunking is a feature of apache. Basically it sends large files out in packets which get reassembled on the other end. It seems like this works for the first time, but the file that gets cached is not the reassembled one.

 

I dunno if my analysis is correct.. Maybe I'm looking in the wrong spot for clues.

 

Anyway, thanks for your help..

 

:beer::headbang::wall:

Link to comment
Share on other sites

These are the same symptoms that my users reported and there was this and another workaround. It has to do with the headers that apache sends and what IE exepcts in its stupidity. The first time the file is sent, Apache tells it that it is a PDF, so IE reads it that way, but since it doesn't know on its own that it was supposed to be a PDF, it doesn't cache the %PDF stuff along with it and corrupts the cached version. Now, if IE sees the *.pdf extension, it stores the cached version properly. If this particular workaround does not work, you can tell your PDFlib or whatever PHP script/library you are using to save the file to disk first and then redirect IE to the PDF itself. I think the second workaround was the one I actually wound up having to use now that I think about it.

Once again, this is not a problem with Apache or PHP, but an IE bug. I promise. I have experience with this. I wrote a PHP script using phplib to create a pdf and many of my users experienced this problem. After the workaround, the problem was solved.

Link to comment
Share on other sites

Thanks for the reply, I really appreciate it..

 

I tried the .pdf extension thing, adding &foo=.pdf to the end of the URL, to no avail. Also, I am not generating the PDFs on the fly. The PDFs are saved on disk already. The PHP code uses a header("location: http://bla/file.pdf"); command to bounce the browser to the PDF file.

 

I tried hard linking to the PDF, (a href, instead of file.php?pdf=whatever.pdf) and cleared my cache, restarted, and still get this problem.

 

It's very disheartening. I read on the apache buglist that it can be fixed by patching apache to never return a 304 code..... I don't want to do this.. :(

 

I never had this problem when using gentoo and apache2. It seems to have started when using MDK10.1.. So perhaps I should look at the differences.

Link to comment
Share on other sites

Well I fixed my problem.. I figured I'd post it here in case someone in the future encounters it. Actually, its all over google so I'm sure lots of people have the problem, just no solution...

 

Anyway, add this to your http config file:

 

<Files *.pdf>

RequestHeader unset Range

RequestHeader unset If-Modified-Since

RequestHeader unset Unless-Modified-Since

RequestHeader unset If-Range

RequestHeader unset ETag

</Files>

 

All these together will make IE think that the cached version of its PDF is out of date, and will load it from the webserver.

 

What a pain... :wall:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...