Adobe Reader 没有书签功能,很不方便,从网上找了添加书签的方法,整理了一下。
这种添加书签的方法有一个缺陷:书签数据是存在Adobe Reader里的,不是与原PDF绑定的,原PDF复制移动后不会携带已添加的书签,选择书签会发生内部错误。
1.确认Adobe Reader首选项中以下选项均选中:
2.新建文件bookmark_page.js,内容如下:
function DateNow()
{
var d, t, s;
d = new Date();
t = d.getFullYear();
s = t + "/";
t = (d.getMonth() + 1).toString();
if( t.length != 2 )
{
t = "0" + t;
}
s += t + "/";
t = (d.getDate()).toString();
if( t.length != 2 )
{
t = "0" + t;
}
s += t;
return( s );
}
function SaveData( data )
{
// data is a array of array(3)
var ds = '';
data.sort();
for( ii = 0; ii < data.length; ++ii )
{
for( jj = 0; jj < 3; ++jj )
{
if( ii != 0 || jj != 0 )
ds += "%#%#";
ds += data[ii][jj];
}
}
// ds = "A1%#%#B1%#%#C1%#%#A2%#%#B2%#%#C2..."
global.pdf_hacks_js_bookmarks = ds;
global.setPersistent( "pdf_hacks_js_bookmarks", true );
}
function GetData()
{
// data is a array of array(3)
if( global.pdf_hacks_js_bookmarks == null )
{
return new Array(0);
}
var flat = global.pdf_hacks_js_bookmarks.split( "%#%#" );
var data = new Array();
for( ii = 0; ii < flat.length; )
{
var record = new Array();
for( jj = 0; jj < 3 && ii < flat.length; ++ii, ++jj )
{
record.push( flat[ii] );
}
if( record.length == 3 )
{
data.push( record );
}
}
return data;
}
function AddBookmark()
{
// get the file name
var thisfilename = this.documentFileName;
thisfilename = thisfilename.substr(0,thisfilename.lastIndexOf("."));
// get the length of total page number
var numLen = this.numPages.toString().length;
// get the current page number
var numPlugInss = this.pageNum+1;
// add 0 before the page number
while( numPlugInss.toString().length < numLen )
{
numPlugInss = "0" + numPlugInss;
}
// get the current date
var currentdate = DateNow();
// create bookmark
var label="《"+thisfilename+"》第"+numPlugInss+"页(共"+this.numPages+"页)" + currentdate;
var cResponse = app.response(
{
cQuestion: label,
cTitle: "添加书签",
cDefault: "无备注",
cLabel: "备注:"
}
);
if(cResponse!= null )
{
var record = new Array(3);
record[0] = label + " " + cResponse;
record[1] = this.path;
record[2] = this.pageNum;
// store the bookmark
data = GetData();
data.push( record );
SaveData( data );
}
}
function ShowBookmarks()
{
var data = GetData();
var items = '';
for( ii = 0; ii < data.length; ++ii )
{
if( ii != 0 )
items += ', ';
items += '"' + (ii + 1) + ': ' + data[ii][0] + '"';
}
var command = 'app.popUpMenu( ' + items + ' );';
// eval() converts the string literal to a number
var selection = eval( command );
if( selection == null )
{
return;
}
var index = 0;
// eval() converts the string literal to a number
index = eval( selection.substring( 0, selection.indexOf(':') ).toString() ) - 1;
if( index < data.length )
{
try
{
if( this.path == data[index][1] )
{
this.pageNum = data[index][2];
}
else
{
var otherDoc = app.openDoc( data[index][1] );
otherDoc.pageNum = data[index][2];
}
}
catch( ee )
{
var response = app.alert( "打开书签错误. 是否删除本书签?", 2, 2, "删除书签" );
if( response == 4 && index < data.length )
{
data.splice( index, 1 );
SaveData( data );
}
}
}
}
function DropBookmark()
{
var data = GetData();
var items = '';
for( ii = 0; ii < data.length; ++ii )
{
if( ii != 0 )
items += ', ';
items += '"' + (ii + 1) + ': '+ data[ii][0] + '"';
}
var command = 'app.popUpMenu( ' + items + ' );';
var selection = eval( command );
if( selection == null )
{
return;
}
var index = 0;
index = eval( selection.substring( 0, selection.indexOf(':') ).toString() ) - 1;
if( index < data.length )
{
data.splice( index, 1 );
SaveData( data );
}
}
function ClearBookmarks()
{
if( app.alert( "确认要清除所有的书签吗, 删除后将不可恢复?", 2, 2, "删除书签" ) == 4 )
{
SaveData( new Array(0) );
}
}
// add button to the View menu
app.addMenuItem(
{
cName: "-",
cParent: "View",
cExec: "void(0);"
}
);
app.addMenuItem(
{
cName: "AddBookmark",
cUser: "设置本页为书签(&B)",
cParent: "View",
cExec: "AddBookmark();",
cEnable: "event.rc= (event.target != null);"
}
);
app.addMenuItem(
{
cName: "ShowBookmarks",
cUser: "转到指定书签(&T)",
cParent: "View",
cExec: "ShowBookmarks();",
cEnable: "event.rc= (event.target != null);"
}
);
app.addMenuItem(
{
cName: "DropBookmark",
cUser: "删除一个书签(&D)",
cParent: "View",
cExec: "DropBookmark();",
cEnable: "event.rc= (event.target != null);"
}
);
app.addMenuItem(
{
cName: "ClearBookmarks",
cUser: "删除所有书签(&C)",
cParent: "View",
cExec: "ClearBookmarks();",
cEnable: "event.rc= true;"
}
);
3.将bookmark_page.js拷贝至<Adobe Reader安装路径>\Reader\Javascripts\下
4.重启Adobe Reader,在View菜单下即有书签功能: