How to refresh automatically on a PDF viewer?

Lei picture Lei · Sep 13, 2011 · Viewed 19.3k times · Source

I am editing LaTeX on my Windows Vista systems. Which I am using pdflatex to generate PDF file constantly.

My PDF viewer is Adobe Acrobat Professional 7, I have to close and open the same file each time to get the new look.

Is there any way to keep the PDF viewer refreshing the PDF pages once it changed?

Answer

Remi picture Remi · Sep 13, 2011

The viewer does not regularly check changes on disk, so short answer: no (unfortunately)

You could however, use your browser to see the pdf file, inside your own html 'webpage' that regularly refreshes the page using javascript.

this is how (including buttons for switching between manual and automatic refreshing):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=windows-1252">
    <title>my pdf</title>

    <script type="text/javascript">
       var timer = null;

       function refresh(){
          var d = document.getElementById("pdf"); // gets pdf-div
          d.innerHTML = '<embed src="myPdfFile.pdf" width="700" height="575">';
       }

       function autoRefresh(){
          timer = setTimeout("autoRefresh()", 2000);
          refresh();
       }

       function manualRefresh(){
          clearTimeout(timer); 
          refresh();   
       }

    </script>

</head>
<body>
   <button onclick="manualRefresh()">manual refresh</button>
   <button onclick="autoRefresh()">auto refresh</button>
   <div id="pdf"></div>
</body> 
<script type="text/javascript">refresh();</script>
</html>

Just save this code as e.g. 'pdfrefresher.html' in the same folder as your pdf. As src of the embed object you use only the filename, e.g. 'myPdfFile.pdf' (not disk or directory). In the code, you can adjust the width and height of the embedded object and the timeout (in milliseconds).