TA的每日心情 | 奋斗 3 天前 |
---|
签到天数: 2383 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法+ t& Q A9 U! D1 U
1、打开编辑的首选项项
. F$ e. t' p# Q7 |/ }* A( T; u, |% N
2、确保下面的选项都被选中9 P+ C7 z' S3 U$ N3 ^0 p
, }. J, G' ^ i% P
3 把下面的代码保存为一个bookmark_page.js文件
9 C. P0 j& o, j' ?$ Y+ p, N& c// bookmark_page.js, ver. 1.0
& A9 Z$ u9 m' p% S// visit: www.pdfhacks.com/bookmark_page/! v/ [# T: K$ f- j& i, G# W/ }
// edit:cjs 2008-02-17 " L5 l( V% L9 w& r6 S
// 1 修改为中文标签
* F4 h4 U% t6 P" n% j// 2 设置书签时可以自动获取当前的书名
$ T, t6 g1 v$ ~! m0 V9 N7 g- X// 3 自动获取当前所在的页码与总页数,方便查阅
; e/ ^! U9 h& A1 s// 4 实现更多功能可以参看Adobe Reader的SDK
% \) |! ~* y: p b8 Z( U- o, B' ]+ V/ ~7 s; P% F
// use this delimiter for serializing our array
6 {' P" l) c' Q% tvar bp_delim= '%#%#';
! x0 f7 ^! a" h" Gfunction SaveData( data ) ...{
* ]! Z" r$ W. j% N // data is an array of arrays that needs) }3 U) B& ^" W# R6 _, B
// to be serialized and stored into a persistent
5 w1 S0 D, |4 z( B // global string
" `. V: |; ]: G var ds= '';
3 ]% c6 {' ]# c* T& D& n for( ii= 0; ii< data.length; ++ii ) ...{, q) f( \7 V9 o: ^0 H
for( jj= 0; jj< 3; ++jj ) ...{
# q7 N6 b8 j4 D( o if( ii!= 0 || jj!= 0 )8 `4 P' O6 a) v( S3 x$ @
ds+= bp_delim;- |7 Z% V; O2 Q6 @' h
ds+= data[ii][jj];
9 Z6 f3 J4 l! c! b+ O% b; B }
- t" t6 Q/ M! H% `, e0 Q }
- K: a# i1 G2 U; Y global.pdf_hacks_js_bookmarks= ds;
Z" T5 q W) K5 |- s2 u f+ L global.setPersistent( "pdf_hacks_js_bookmarks", true );+ i/ P7 W% F5 j4 ^8 q$ p
}3 X- c. A2 c3 P5 J
function GetData() ...{
. X5 t! ~2 z& P$ Y/ w // reverse of SaveData; return an array of arrays ]$ q: B9 i9 \+ ]
if( global.pdf_hacks_js_bookmarks== null ) ...{, C1 P9 h1 m' p8 E( b
return new Array(0);2 V! |2 i) r6 h( @2 Q2 K8 P
}
! C& @' z% n: H/ n4 a var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );+ q0 S2 x( E+ f+ E% |- W
var data= new Array();7 P3 Z/ J* a% N' o
for( ii= 0; ii< flat.length; ) ...{ o2 M/ e/ H" `: A$ Z' r0 D+ l! j3 N
var record= new Array();
$ h. ^& W4 g/ o: @. [ for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{. ^4 S* V, f% T2 l/ C3 O2 t, h& R- g( O
record.push( flat[ii] );) w7 J+ L, f# t& y/ \
}: j4 K- U* Y3 w, Z$ t
if( record.length== 3 ) ...{
, L$ n: r# t) E data.push( record );# ?( c* m% g5 n
}
0 z% ?) z2 }- Q }- D$ w. X- Z% \" A4 ^# f. X
return data;
4 o, a3 ^# d3 o# n) \- x}
/ @: Q# s# {, N. I//Get Current Date/ Q1 ]4 N$ d" w; a9 S( y
function DateNow()...{
* ~/ d3 w4 C6 q: T var d, s ;1 F5 k; Q' Z! J* A5 g$ _! A
d = new Date();
7 T1 y" |/ {- S# A2 m, ?# F s = d.getFullYear()+"/";
6 H1 Q8 D: c% i8 Y s += (d.getMonth() + 1) + "/";
8 |0 b: M, g% ^0 j2 @0 m/ x0 Q s += d.getDate() ;$ G, G; t# G, C9 F' x+ ]
/**//*
2 J: q5 b& v V% |! v% @ s += d.getHours() + ":";
6 @1 T( V( d" k! |! r' X s += d.getMinutes() + ":";% l: S6 m" I& P
s += d.getSeconds() ;8 `. J2 t# i m1 {! x* m
*/1 s+ y, q. e: ]% D- x5 X s
return(s);
+ {; w) A3 V5 i" B. r* a: B}
- p2 ?4 U# [, d1 Z- _6 S/ O+ ~4 a/ F ]2 R. n
function AddBookmark() ...{
& @1 e7 ~) X5 O/ S- _/ `! ] // query the user for a name, and then combine it with# s9 ^- ]6 H6 L: x) J
// the current PDF page to create a record; store this record
5 S' B, o U; _( [# u* B; a ] var thisfilename=this.documentFileName;- q# Z, a1 y3 J2 c. c' q
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
8 K$ z3 M1 w q var numPlugInss=this.pageNum+1;
# D+ E7 v9 E6 w7 Y! \, N* S& [% H: y9 G var currentdate=DateNow();
2 s6 m5 @* @; w# @" \1 I var label= ' I& F- U3 j; r
app.response( "书签名称,可以修改以便于记忆:",
+ B+ e8 n" P/ g6 M s "书签名称",9 K& T6 X( c5 v
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,$ C1 N7 [$ z# b/ {
false );5 l* x: h3 i5 J4 G
if( label!= null ) ...{
# x4 }; ^( o1 [ var record= new Array(3);" F- @* s, T5 g, b& S4 z2 I- D+ y
record[0]= label;4 O) m2 b; p- @5 D
record[1]= this.path;. J- E# O/ F; T! \ w9 r5 U$ {6 r) ^+ ~
record[2]= this.pageNum;# s8 d& R9 _% g6 x) I! A+ V
data= GetData();
) I( J! e ~- ~% j& K data.push( record );8 y- m1 a2 b. j( M" m
SaveData( data );# l: E& g v; J7 U: S
}/ y1 N9 r' D6 N" k1 ]# {
}
% B* C$ M4 L9 e! p: n: ~/ s7 _function ShowBookmarks() ...{
, j. A2 z: F, n6 e. ~& S, R6 l8 s6 J0 M // show a pop-up menu; this seems to only work when
* r- p6 o; z9 l2 K4 F8 `! F; F // a PDF is alreay in the viewer;
( t2 E2 \& b1 o7 z! r$ [4 b! q var data= GetData();8 a" j3 Z1 e) Z& X
var items= '';
* \% s4 X- [5 u; x for( ii= 0; ii< data.length; ++ii ) ...{
9 y4 t, [8 ~: v+ k! X C if( ii!= 0 )2 q( N+ ?! ?. m( C- `% L7 f
items+= ', '; @7 w, B I6 l; r. I, k1 e0 R
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
6 i( o8 e. U8 M& h' ]6 ^1 T }
3 ?) a0 p) P1 \& J5 S: o // assemble the command and the execute it with eval()0 K% L4 i) {+ Y2 W2 _) s0 o
var command= 'app.popUpMenu( '+ items+ ' );';
( D; J: j! H1 \0 W' p/ p var selection= eval( command );# P E/ @# r/ J
if( selection== null ) ...{4 S% q! ^; X: i
return; // exit3 [: p' t1 U; L9 j* E+ f
}
/ z# d9 V4 x+ Q" p6 { // the user made a selection; parse out its index and use it* G) U5 v( C& Y$ @ ^8 E
// to access the bookmark record. c0 K" E w9 H P1 g
var index= 0;
" d. z/ T# K0 J // toString() converts the String object to a string literal
. O# |8 l' z) U8 o9 ?$ e // eval() converts the string literal to a number
5 p" _$ f1 r: X* p3 k3 ~' k index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );6 |! U2 b/ \" _7 j- c
if( index< data.length ) ...{" g9 i! h H6 j) I
try ...{
8 E" x% v4 O# t4 G: E // the document must be 'disclosed' for us to have any access( x; z! [ _* @6 j) W' p& M- T4 o
// to its properties, so we use these FirstPage NextPage calls9 g* e" O7 z* y, S& { v3 x7 A5 O" g/ |" t
//3 }# z" i- }, C% I, W
app.openDoc( data[index][1] );& H; D5 b0 u% P8 m
app.execMenuItem( "FirstPage" );
% e3 z% b7 [0 c7 e. z+ R4 @ for( ii= 0; ii< data[index][2]; ++ii ) ...{+ F- m/ J/ R5 O' y9 Q+ \
app.execMenuItem( "NextPage" );
* u1 {9 x; \ W6 I7 M& d/ ~ }& O1 K9 ~4 e' S- @* K! g
}
2 {- J" T9 S" S$ l2 G catch( ee ) ...{+ D L: n9 T& o4 T1 I! I# p7 M
var response= : a) k K/ \ O4 o8 C
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");, W, s8 J% M$ z5 k/ L! r
if( response== 4 && index< data.length ) ...{
& z7 T% [3 V9 p6 o" P data.splice( index, 1 );
# O6 N; ^$ g m% n' _/ s SaveData( data ); v z3 ]) M N8 ?6 o5 M0 Z
}* V# [3 r" ]0 f* P
}( q K' B2 e+ ?6 W S
}; m7 h. ?* a& v/ w
}
6 A& u5 s8 i4 T" i3 d Z9 ?5 Gfunction DropBookmark() ...{
3 B/ N/ u2 [2 ` // modelled after ShowBookmarks()
: X* K' P3 k! t# p$ J( E var data= GetData();
; a3 ?0 n2 S. w9 t1 v1 q/ N: l3 S/ F var items= '';% R, f- K' Y5 n6 p
for( ii= 0; ii< data.length; ++ii ) ...{
T: O( ^% W5 h4 ]/ s: p1 C if( ii!= 0 )3 Z0 |" N& u5 x& v8 C
items+= ', ';
# d1 v" n9 F! t, e+ p items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
6 h+ [" T6 b: w }' ^- n& E- X8 ~% x; D/ K' N2 ^
var command= 'app.popUpMenu( '+ items+ ' );';. A. y9 }0 D+ x% F- \3 \ q6 y: r
var selection= eval( command );( X5 z7 W7 \$ p2 j6 i7 E
if( selection== null ) ...{
- V* K$ y3 j2 T. W return; // exit
& W9 P7 M3 C! `- J4 W! c }
& l# s* H" R6 j- ~% I var index= 0;, U" P9 H. S5 g# H4 f( t2 r
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
% R' X0 o! W" V/ z2 I3 z if( index< data.length ) ...{, H( @" ^9 q# ^6 `
data.splice( index, 1 );0 X$ o8 x/ {3 @1 q3 |0 h M
SaveData( data );
( F$ a/ a! i+ ]/ Z# Z8 l; f O }: X6 k$ \, v3 m: K m# H; V2 |
}6 c/ l; T \8 W6 K7 d
function ClearBookmarks() ...{
, F( \( G" h6 X: c. j if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
& B) X+ X, L/ w7 [6 R2 `6 o; N SaveData( new Array(0) );3 _9 s. ]+ }1 S4 h1 @7 F/ }% h
}4 k; C! [$ D6 l1 t, j& K( P9 m
}) G" ~$ y- R) E5 B
app.addMenuItem( ...{1 c* s. {2 }* L% T H! Y1 E
cName: "-", // menu divider
1 S) r; R9 h2 e) c/ d1 v* BcParent: "View", // append to the View menu
u4 i5 ^4 c ~ gcExec: "void(0);" } );
! z: r9 v/ H5 {1 `4 J& c. \app.addMenuItem( ...{
5 b/ f% g8 K$ }" _% A& M mcName: "设置本页为书签(&B)",
0 }5 b! Z6 L0 l0 EcParent: "View",
/ I* a1 R' _# N4 rcExec: "AddBookmark();",2 [- k9 G& E2 P3 _7 W$ A) l
cEnable: "event.rc= (event.target != null);" } );
( P( s' H3 c/ Y, `app.addMenuItem( ...{
, c3 \3 Z" i% D+ U1 z( H6 KcName: "转到指定书签(&T)",& V' [/ q# P0 Y' [ A. @4 V0 ^& U
cParent: "View",
- t W4 v u1 u! e& M9 h& wcExec: "ShowBookmarks();",2 B/ p! Z8 J6 X6 y& N0 n7 v5 J& O# `
cEnable: "event.rc= (event.target != null);" } );
' Z: _0 D& u+ l: F) \$ R//cEnable: "event.rc= true;" } );
$ q$ B p7 y) A/ O/ |0 d4 ~app.addMenuItem( ...{
% o9 v$ H, Q: ~& Y4 tcName: "删除一个书签(&D)",6 [0 X4 o7 Z' s' l" Q
cParent: "View",; H0 r: P z+ X% Z
cExec: "DropBookmark();",
3 ~" C8 {8 H0 e- @2 }& I8 IcEnable: "event.rc= (event.target != null);" } );( ^7 @. i+ Q: G
app.addMenuItem( ...{0 V7 Q0 t& W$ H- p( X9 z" H) P
cName: "清除所有书签(&C)",
3 s) \0 d* M8 I& FcParent: "View",
1 E& f) C" N) L; _; o) ecExec: "ClearBookmarks();"," _& f0 Q" c+ T, J( L
cEnable: "event.rc= true;" } );
* i# d. C* B M4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下# I. `# G9 q3 ?: ^. V
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
; k! m7 J' {* {8 Z. G* W; h
r. y+ N: a. k2 t- ?1 f0 }* H# b& ]+ G, T
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|