Open updated PDF file

Asked

Viewed 326 times

0

Well, I have a PHP system that builds a PDF. After that, I have a common html link that opens the pdf on the screen normally, until then everything ok.

However if I modify the content of the PDF, and give the command to the system to rebuild it with this new information, when clicking on the link to open, it opens the old pdf, I can only view the new one if you give a "F5".

Does anyone know an alternative to always open the already updated file and not the cache version?

PS: the link opens the ready file that is saved on the server.

  • 1

    try to put a variable that always changes in the link, eg: www.meusite.com/arquivo.pdf?n=093904. So every time we change this ?n= it will not find anything cached, and will open the new pdf

  • This should work. But it’s not exactly what I wanted, anyway, if I don’t get another way I’ll apply it. Thanks Leonardo

2 answers

2


A better approach would be to use the header() to inform the browser that the content of the request must not be cached.

header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1
header('Pragma: no-cache'); // HTTP 1.0
header('Expires: 0'); // Proxies

Source: Preventing cache of inline PDF

1

There are several ways to solve this problem, from html to javascript. However the easiest one would be to create a variable link, being by the name of the pdf file or by a parameter:

echo '<a href="files/pdfs/filename.pdf?q='.microtime(true).'">PDF</a>';

The most reliable way would really always change the name of the pdf file. However it is not very practical or cool. A parameter in the URL works almost 99% of the time

Source: stackoverflow in English

Browser other questions tagged

You are not signed in. Login or sign up in order to post.