[pdftex] ``Reload'' function for Adobe Reader (Linux)

James Quirk jjq at galcit.caltech.edu
Fri Jan 23 15:22:58 CET 2009


Alexander,

On Thu, 22 Jan 2009, James Quirk wrote:

> > 
> > James, I tried your code. Unfortunately, my acroread (8.1.3) crashes
> > (sementation fault) if there is more than one document open.
> > 
> > I found out that it is currentDoc.closeDoc() which fails if the event
> > is triggerd by clicking the tool button. The object currentDoc, however,
> > is valid, as I can output currentDoc.path to the console.
> > 
> > Alexander
> I've just posted a bug report to the Adobe Reader Unix forum, see:
> 
> http://www.adobeforums.com/webx/.59b795d7
The problem has been acknowledged as a bug and there is a chance it will 
be fixed in future AR releases. In the mean time, I've come up with a 
slightly cleaner workaround than my earlier effort. It uses a JavaScript 
closure to hide all its machinations. The script is undocumented,
but as it might be of general interest, I'm attaching a copy below.

Regards,

James

function getReload(id) {
   var _closure = function () {
      // the closure object
      var c = {}; 
   
      // private data
   
      var obj = id;
      var doc;   
      var path;
      var view;
   
      // private routines
      var pcall = function(f) {
         c._pcall = f;
         var run  = app.setTimeOut(obj+"._pcall()",1);
      }
       
      var closeDoc = app.trustedFunction(function() {
         app.beginPriv();
            view = doc.viewState;
            path = doc.path;
            doc.closeDoc();
            pcall(openDoc);
         app.endPriv();
      });
   
      var openDoc = app.trustedFunction(function() {
         app.beginPriv();
            var oDoc = app.openDoc(path);
            oDoc.viewState = view;
         app.endPriv();
      });
     
      // public interface
    
      c.reloadDocument = function(hdl) {
         doc = hdl || event.target;
         pcall(closeDoc);
      };
     
      c.addToolButton = function(label) {
         app.addToolButton(
            {
              nPos:      0,
              cName:     "Reload",
              cTooltext: "Reload Current PDF",
              cLabel:    label || "Reload",
              cEnable:   "event.rc = (event.target != null);",
              cExec:     obj+".reloadDocument();"
            })
      };
   
      c.addMenuItem = function(label) {
         app.addMenuItem(
            {
              nPos:    0,
              cName:   "reloadCurrentDoc",
              cUser:   label || "Reload",
              cParent: "File",
              cEnable: "event.rc = (event.target != null);",
              cExec:   obj+".reloadDocument();"
            })
      };
   
      return c;
   }
   // assign closure 
   eval (id + "=_closure();");
}

   
getReload("abc");
abc.addMenuItem();
abc.addToolButton();


More information about the pdftex mailing list