title: Adobe Acrobat Reader Tabs Saving And Autoloading
body: <p>I've created Javascript for Acrobat Reader which allows you to save the currently open tabs. It adds the menu items: "Save tabs", "Load tabs", and "Toggle auto load". It saves tabs and page numbers, and restores them as well. </p>
  
  <p>It's especially helpful for Linux, where there aren't many pdf readers available. However, I haven't been able to figure out how to catch open or close document events, or to set some timer event to automatically store current list of tabs. </p>
  
  <p><a href="https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf" rel="noreferrer">Here is the original API reference</a> for Adobe Acrobat.</p>
  
  <pre><code>/*
     Here is the script, put it in $HOME/.adobe/Acrobat/9.0/JavaScripts (or in 
     the equivalent program files folder under Windows,) and it will automatically
     be loaded. 
  
     When you need to save current state, choose menu "view -&gt; Save Tabs", to restore 
     recently saved tabs choose "view -&gt; Load Tabs". 
  */
  
  var delim = '|';
  var parentMenu = "View";
  
  /*
   Loading Saved Tabs
  */
  function LoadTabs() {
  
    if (global.tabs_opened == null) {
      return;
    }
  
    var flat = global.tabs_opened.split(delim);
    for (i = 0; i &lt; flat.length; i += 2) {
      try {
        app.openDoc(flat[i]);
        app.execMenuItem("FirstPage");
        for (ii = 0; ii &lt; flat[i + 1]; ++ii) {
          app.execMenuItem("NextPage");
        }
      } catch (ee) {
        app.alert("Error while opening the requested document.\n" + flat[i], 3);
      }
    }
  }
  
  /*
   Function with trusted section returning opened documents
  */
  trustedActiveDocs = app.trustedFunction(function () {
    app.beginPriv();
    var d = app.activeDocs;
    app.endPriv();
    return d;
  })
  
  /*
   Saving Tabs that are opened
  */
  function SaveTabs() {
    var d = trustedActiveDocs();
    var tabs = '';
  
    for (var i = 0; i &lt; d.length; i++) {
      if (i &gt; 0)
        tabs += delim;
      //    app.alert(d[i].path+"------"+d[i].pageNum,3);
      tabs += d[i].path;
      tabs += delim;
      tabs += d[i].pageNum;
    }
    global.tabs_opened = tabs;
    global.setPersistent("tabs_opened", true);
    app.alert("Tabs Saved", 3);
  
  }
  /*
   Toggle auto load tabs
   automatically loading tabs when reader starts
  */
  function ToggleAuto() {
    if (global.tabs_auto == 0 || global.tabs_auto == null) {
      global.tabs_auto = 1;
      global.setPersistent("tabs_auto", true);
      app.alert("Tabs auto loading enabled", 3);
    } else {
      global.tabs_auto = 0;
      global.setPersistent("tabs_auto", true);
      app.alert("Tabs auto loading disabled", 3);
    }
  }
  
  
  app.addMenuItem({
    cName: "-",
    cParent: parentMenu,
    cExec: "void(0);"
  });
  
  app.addMenuItem({
    cName: "&amp;Save Tabs",
    cParent: parentMenu,
    cExec: "SaveTabs();"
  });
  
  app.addMenuItem({
    cName: "&amp;Load Tabs",
    cParent: parentMenu,
    cExec: "LoadTabs();"
  });
  
  app.addMenuItem({
    cName: "Toggle auto load",
    cParent: parentMenu,
    cExec: "ToggleAuto();"
  });
  
  if (global.tabs_auto == 1) {
    LoadTabs();
  }
  </code></pre>