admin管理员组文章数量:1289565
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.
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.
Here is the original API reference for Adobe Acrobat.
/*
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 -> Save Tabs", to restore
recently saved tabs choose "view -> 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 < flat.length; i += 2) {
try {
app.openDoc(flat[i]);
app.execMenuItem("FirstPage");
for (ii = 0; ii < 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 < d.length; i++) {
if (i > 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: "&Save Tabs",
cParent: parentMenu,
cExec: "SaveTabs();"
});
app.addMenuItem({
cName: "&Load Tabs",
cParent: parentMenu,
cExec: "LoadTabs();"
});
app.addMenuItem({
cName: "Toggle auto load",
cParent: parentMenu,
cExec: "ToggleAuto();"
});
if (global.tabs_auto == 1) {
LoadTabs();
}
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.
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.
Here is the original API reference for Adobe Acrobat.
/*
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 -> Save Tabs", to restore
recently saved tabs choose "view -> 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 < flat.length; i += 2) {
try {
app.openDoc(flat[i]);
app.execMenuItem("FirstPage");
for (ii = 0; ii < 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 < d.length; i++) {
if (i > 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: "&Save Tabs",
cParent: parentMenu,
cExec: "SaveTabs();"
});
app.addMenuItem({
cName: "&Load Tabs",
cParent: parentMenu,
cExec: "LoadTabs();"
});
app.addMenuItem({
cName: "Toggle auto load",
cParent: parentMenu,
cExec: "ToggleAuto();"
});
if (global.tabs_auto == 1) {
LoadTabs();
}
Share
Improve this question
edited Dec 24, 2018 at 17:19
Jeff Axelrod
28.2k33 gold badges150 silver badges248 bronze badges
asked Oct 2, 2012 at 11:08
Andrey KartashovAndrey Kartashov
1,4211 gold badge13 silver badges20 bronze badges
1
- 1 Just wanted to say thanks, this is super useful! This page helped me out with installing it. – Luke Davis Commented Oct 16, 2016 at 8:22
1 Answer
Reset to default 3Thanks for the fantastic start to implementing this glaring feature omission from a mature product. An Autohotkey script will acplish what you're looking for. I've created one below that will automatically save the tab layout when you close Acrobat.
This script works with the latest version of Acrobat Pro DC. In this version, the script menu options appear at the bottom of the "view" menu. If your version differs, you'll have to modify this script; please report in the ments if your Acrobat version puts the custom Javascript menu options elsewhere.
if WinActive("ahk_class #32770") & WinActive("Adobe Acrobat", "Do you want to close all tabs or the current tab") {
Send, !c
WinWaitActive, ahk_class AcrobatSDIWindow
Send, !v{Up 3}{Enter}
WinWaitActive, Warning: JavaScript, Tabs Saved
Send, {Space}
WinMenuSelectItem, ahk_class AcrobatSDIWindow, , View, Save Tabs
Send, ^q
}
本文标签: javascriptAdobe Acrobat Reader Tabs Saving And AutoloadingStack Overflow
版权声明:本文标题:javascript - Adobe Acrobat Reader Tabs Saving And Autoloading - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741406546a2376978.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论