7
votes

I was trying to find a way to prevent browsers from caching PDF that is being loaded using a streaming methods.

FireFox and Chorme deals just fine with the following headers and doesn't cache any pdf file:

Response.AddHeader("Pragma", "no-cache, no-store"); Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0"); Response.AddHeader("Expires", "-1");

Although, IE 7 (with acrobat reader 9.4.1) works only with the following headers and prevent the caching of the PDF doc:

Response.AddHeader("Pragma", "no-cache, no-store"); Response.AddHeader("Cache-Control", "private, must-revalidate, max-age=0"); Response.AddHeader("Expires", "-1");

When i was trying to use IE 7 with Acrobat Reader 10, the above header didn't make any different and cached the PDF no matter what i tried.

When i am trying to put Cache-Control: no-cache, no-store, the pdf was not loaded at all. According to my understanding, IE use the cache mechanism to load the PDF documents.

Is there anyone familiar with a global or specific way (by using other headers for example) that can help prevent caching of PDF documents?

4

4 Answers

7
votes

Add a random number to the URL, either in the path or in the query string. That way, it'll download the file every time. You could also change the number only, if the file has changed, for example using the mtime of the file.

PHP (since everybody understands that, even if nobody likes it):

 <a href="document.pdf?buster=<?= time() ?>">Download PDF</a>
1
votes

This issue of showing PDF (and other document types) inline with the use of the no-cache header has been filed as a bug to Microsoft: http://support.microsoft.com/kb/316431. IE uses its own caching mechanism when reading PDFs inline.

Unfortunately, the folks at M$ said this "works as designed" and users should not use the no-cache header... go figure.

You could try VSU's idea of using a Java PDF reader... I may go this route too.

0
votes

Controlling the cache settings down the pipe is not fool proof. The alternative is to encode the realtime and date in the file name of the PDF.

0
votes

You can encode the time date into the filename of the PDF so that each time a request is made the filename is unique.

Response.AddHeader "Content-Disposition","attachment;filename=somename" + CurrentDate() + Currenttime() ".pdf"

CurrentDate adn CurrentTime are imaginary functions. You need to write that code.