Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Prevent Caching When using PDF Streaming with Acrobar Reader 10.0 (HTTP1.0/HTTP1.1)

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?

like image 333
Niv Avatar asked Jan 18 '11 13:01

Niv


People also ask

Do PDFs get cached?

Indeed, this happens at least in Chrome and Edge browsers. It happens because the pdf file that you pass to the viewer (iframe or PDFObject) is always cached internally with the same name. You can solve it add a random number or date and time as the name of the pdf.

Why are PDF viewers so slow?

PDFs can be slow because they hold too much data or contain unnecessary objects inserted by the programs that created the PDFs.

How do I turn off security on a PDF?

Choose “Tools” > “Protect” > “Encrypt” > “Remove Security.” Remove Security: The options vary depending on the type of password security attached to the document. If the document has a Document Open password, click “OK” to remove it from the document.


1 Answers

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>
like image 108
iGEL Avatar answered Sep 19 '22 17:09

iGEL