TA的每日心情 | 奋斗 昨天 10:28 |
---|
签到天数: 2370 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法+ V+ D9 e$ l5 o) Y+ P
1、打开编辑的首选项项
4 x& I- b3 y* k( a i9 ]9 R" D7 W0 O* s1 A3 Y
2、确保下面的选项都被选中
, D" m- G( u1 s8 P3 k% J J
0 m { ] w ]+ \/ j. R2 s3 把下面的代码保存为一个bookmark_page.js文件
( ^/ ?0 V/ u2 L. T, g// bookmark_page.js, ver. 1.0
. ]3 x: N+ y9 i; F5 p// visit: www.pdfhacks.com/bookmark_page/8 t$ Q3 M' p- L/ W# m
// edit:cjs 2008-02-17 $ T" D' f2 ^ P6 K% Z% J4 s; x& h- `
// 1 修改为中文标签6 V) R8 G6 U3 E
// 2 设置书签时可以自动获取当前的书名4 j8 C3 D/ t3 M' Q6 Q- u% o5 C
// 3 自动获取当前所在的页码与总页数,方便查阅7 F& H9 ~8 l* _
// 4 实现更多功能可以参看Adobe Reader的SDK
* M2 {5 b+ G* x4 z
. O6 O' r$ D$ }$ p// use this delimiter for serializing our array
& p1 w; i7 `; m) S$ Hvar bp_delim= '%#%#';
% u1 |5 d" n' nfunction SaveData( data ) ...{/ y$ S' G2 P1 t1 q1 l" `
// data is an array of arrays that needs
. `8 k% a. E& M; i1 u, K // to be serialized and stored into a persistent
# [+ S! Y* A4 ^& A+ F // global string
, E& C f5 q g% Y% D7 d7 m var ds= '';! e6 P( u# Z9 y" E2 `% i4 B3 v% A
for( ii= 0; ii< data.length; ++ii ) ...{; i' _) m) B5 O. L5 m, a: K% P
for( jj= 0; jj< 3; ++jj ) ...{
4 F$ J+ w% e1 B5 I! i# } if( ii!= 0 || jj!= 0 )
- a! s8 j* `4 o6 @9 z6 w3 X ds+= bp_delim;) u- n) _) Q- S/ z
ds+= data[ii][jj];' U& h- Q% t5 M. q0 C& E \ X7 N# }
}
& Y5 F, r% H0 M: s- l }5 G( j7 g& b8 I, L8 i
global.pdf_hacks_js_bookmarks= ds;3 y% _0 b$ ~7 i' [) {. q& O
global.setPersistent( "pdf_hacks_js_bookmarks", true );
% _) X; a/ J6 F1 t" C}+ q3 Y3 K6 v% U$ Y: J T/ P1 k- J
function GetData() ...{
r2 J2 L1 v. ]) }, c, x" E // reverse of SaveData; return an array of arrays
$ }- v# ?+ J& {8 ]5 P if( global.pdf_hacks_js_bookmarks== null ) ...{
1 A" H9 b- D0 N7 ^" c7 i3 e8 i9 ` return new Array(0);
$ M2 ]6 I# n0 q% N* G8 n1 c* T }
* h p* l! D7 F0 P5 P var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );/ b$ ?% H& G6 t+ U+ b# P2 P+ l+ n9 w
var data= new Array();
# A' _* V/ ]" I for( ii= 0; ii< flat.length; ) ...{
X. S* g1 ^4 B# K$ I% T* X var record= new Array();) w3 s" Z0 ~ T% L4 K
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
0 H" ^, P# v: h& D1 n/ V% X record.push( flat[ii] );+ F: ^1 T, o* |' s z1 b5 E
}6 i" v3 _0 O) E* y+ R: h) m S
if( record.length== 3 ) ...{. O+ T7 M+ I/ h$ P f
data.push( record );1 O) b* a4 U R. V0 k
}
{+ n- P# A+ D4 n6 b6 s8 _: z }) }! d: w Y9 }
return data;
; C! z& x1 [( z0 H! a- x% F9 L}
9 m1 ^; ?9 Y# t//Get Current Date z. w! M8 S" l% O! n( h: v% K
function DateNow()...{, P1 E% x) {( y" Y( n6 d4 G% }
var d, s ;
" Q {. R+ L2 H! X' s5 m1 I d = new Date();
5 b3 J! }* P7 A. _1 f9 P) J s = d.getFullYear()+"/"; T! g* w/ L& ?% N7 a7 o2 V
s += (d.getMonth() + 1) + "/";
, T# f! X% }. `) j/ T% Y s += d.getDate() ;2 B l( q" q; H+ O! m4 |! s
/**//** o$ L* b' b% N" `( e+ s
s += d.getHours() + ":";- ]# Z% m- m" ^8 F
s += d.getMinutes() + ":";
$ y, x1 @: {- j7 d7 ?. t) M2 E& w/ I8 | s += d.getSeconds() ;" K& [/ `2 Y' U, q
*/
4 e: j: K1 ?6 ~0 ]& v0 I. s return(s);
# q' U* x5 q% `# A- |}4 e' H! i4 T9 Y) N, c9 L
! p7 i, y% P8 afunction AddBookmark() ...{! v3 c% [& h+ O8 ]& r" D
// query the user for a name, and then combine it with! ?8 ^/ _9 d/ R
// the current PDF page to create a record; store this record, D4 I5 [0 a; h/ c: F$ E
var thisfilename=this.documentFileName;, r( X V; S5 @9 V6 p. P7 l
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));3 ~1 @) ]! ]1 u$ M/ a
var numPlugInss=this.pageNum+1;0 @: ^5 H& M% g/ S& |, h
var currentdate=DateNow();
) Y- N7 C# e9 h var label=
' G! e. }1 @ _/ f" J2 \( w6 x app.response( "书签名称,可以修改以便于记忆:",8 y* Z+ N( }' R' _1 }# {- M
"书签名称",
[3 N! l/ ?9 |& y& K; x3 D "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,2 R7 ]: Z1 Y! { ~. n. D2 m
false );
7 M3 }: e5 ~1 Y/ c if( label!= null ) ...{
& z4 Y) X# h9 ^# n var record= new Array(3);
+ w# c, S" l# t& f record[0]= label;/ m" Q8 ]0 m! n% R: C5 m/ G
record[1]= this.path; {: Y, L# D9 p5 k% C ]
record[2]= this.pageNum;
1 l9 q) h8 E8 p+ R data= GetData();0 V; H1 {! p4 \; f _; L
data.push( record );
, Y; w7 |* M% m; G) j6 x5 {" { SaveData( data );
' L4 B ^, ?" C! d9 n/ F6 Q }/ [! E9 E' n+ e$ |
}8 d7 }2 f( u; y4 D2 d, ~* K
function ShowBookmarks() ...{! n/ ^% r) F% d9 c& C. z
// show a pop-up menu; this seems to only work when5 l. ?' [1 z1 ]; |* E
// a PDF is alreay in the viewer;
. \3 q1 |( L/ L$ s9 p5 j1 n var data= GetData();
j8 S: e7 S. d- H var items= '';$ Q0 K% m/ v: C
for( ii= 0; ii< data.length; ++ii ) ...{* v K; I! x( W" Z) ~- H
if( ii!= 0 )7 [% L" t8 h6 ]# J1 a6 F
items+= ', ';
. A+ I. Q7 p; i4 f% O5 ^ items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
; j0 E' g' y' u6 p7 `) m }0 o) b- r a; M) A" m# V% `
// assemble the command and the execute it with eval()
* \" @! w5 {0 U var command= 'app.popUpMenu( '+ items+ ' );';
3 C$ g# P5 z& s' `, N% t, q6 ] var selection= eval( command );
7 w' Q+ Q! U. s5 ]" w! D if( selection== null ) ...{
2 P5 H8 |0 {3 M7 G' w( A2 V0 q return; // exit
* M1 w" q- J% m3 L, R }
% q F3 U" X; e0 T7 ] // the user made a selection; parse out its index and use it
$ ?6 T0 P1 b+ a0 V2 h4 Q* k // to access the bookmark record
. s$ i6 ^% ]7 t: w; y var index= 0;" `3 k, |1 @$ V3 t# ]# ~- z. D
// toString() converts the String object to a string literal
# q. N0 o$ A5 Q# P& H# G // eval() converts the string literal to a number
" L# g5 u5 \1 c0 E: o index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
4 u4 B# G4 q! ~; D2 d. b' u if( index< data.length ) ...{
p: d7 I, V7 }: v x try ...{- a! v) v8 A2 c/ m/ ?3 Z) a
// the document must be 'disclosed' for us to have any access k6 c+ X4 c& c: B1 _( ?! S
// to its properties, so we use these FirstPage NextPage calls3 f% z" o1 ]4 H. d1 l
//
( Z. t9 b: y9 F app.openDoc( data[index][1] );$ v6 l7 }9 |7 m. {' E
app.execMenuItem( "FirstPage" );
+ _7 S. w: i% A6 X for( ii= 0; ii< data[index][2]; ++ii ) ...{
& ?( S: a) _0 }. D# c" T( f' [, v( I app.execMenuItem( "NextPage" );
+ y. O& y7 N6 `/ D" w$ v @. h }) \7 d2 f; R3 z! D
}
+ M2 p- o7 N( `; M$ [% z0 X$ A6 _ catch( ee ) ...{
# V! J" w- V6 |0 _7 G8 P1 b7 Q var response=
& z" l: d6 h* ]. Q, H U, s app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");
* L: a# V2 f4 [) c9 X! t. [3 B if( response== 4 && index< data.length ) ...{9 X( @. I3 c: e* Q* K
data.splice( index, 1 );
/ g6 y7 J8 l3 s# n5 E0 d6 M SaveData( data );
_* t* y: \, }/ O' o6 r5 A }
" Z/ t% V b4 n' g# x7 W7 J }/ D* V4 x v" t2 `4 q7 x
} n* i" L |2 r
}
0 T. T2 b8 f' R. d- h6 ^function DropBookmark() ...{. j+ l& e6 J# G/ W8 b
// modelled after ShowBookmarks()- o, G U! k) J6 b- @, s
var data= GetData();
! w4 p/ ]+ e' i% C) k( K var items= '';
% \% g, Y6 o" s# S- i% q( f for( ii= 0; ii< data.length; ++ii ) ...{+ R' U! e* m/ t3 q J$ o$ p p
if( ii!= 0 )
+ L! I* K+ J5 C items+= ', ';
! F8 n c3 J9 h' Y4 G& K: ^ items+= '"'+ ii+ ': '+ data[ii][0]+ '"';7 q8 G6 {2 ^3 \
}+ O; Y. G& H+ u; A
var command= 'app.popUpMenu( '+ items+ ' );';* k/ Y1 S n9 v# l' W" ]
var selection= eval( command );# _4 o! A3 q4 o* z3 X6 \9 G' v
if( selection== null ) ...{
: i# g1 X7 D$ A( ?8 _5 n return; // exit. v. o$ P; [# @+ U
}! z5 X' {: S( C: r" ]$ N$ ~
var index= 0;
9 h/ p3 O% w Z) L* P index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );0 b$ ^. ^7 s/ p2 v
if( index< data.length ) ...{3 {7 w, e) G! {; b
data.splice( index, 1 );
1 g7 m' ?* v& S* g1 T SaveData( data );
8 g5 m0 m5 X$ i. Z }1 b3 j$ C8 z+ B) @$ B# w6 ~8 k
}- q3 C ] K" E6 r2 q9 g' a
function ClearBookmarks() ...{/ Z, e1 G* V L! m8 S6 N7 S& ?
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{4 {. T4 ]( c9 ?, n3 n- [
SaveData( new Array(0) );5 D- \. z5 U2 `/ }0 K% x1 x, X
}
/ N$ J) y. ^ ], N9 C/ J}: f7 V# i( w- d% a* R
app.addMenuItem( ...{* E% j& G. d8 _% S
cName: "-", // menu divider4 U+ P2 v$ l" S; ?2 O3 ^* `0 I: K
cParent: "View", // append to the View menu, M6 D; L4 t6 j" o& F" |
cExec: "void(0);" } );* z; u# G, b9 i) a# _% |3 U+ M
app.addMenuItem( ...{
5 p! Y7 c* {4 W" S& UcName: "设置本页为书签(&B)",
# r* R3 ]9 Z4 V+ n# l1 R) JcParent: "View",
# C' v7 g0 I7 q8 ~1 Z* c; [cExec: "AddBookmark();",. N. |5 S+ o$ o' W7 ?
cEnable: "event.rc= (event.target != null);" } );# E3 y, U; p" g# e- S& a
app.addMenuItem( ...{
) o; C4 u, w0 T% ^# AcName: "转到指定书签(&T)",
2 e4 M. d- f1 \* a, d, U# wcParent: "View",
+ E* Z9 Q Y7 ycExec: "ShowBookmarks();",- |( y+ e/ _ `) ?6 @1 {; n
cEnable: "event.rc= (event.target != null);" } );
( b: U* g$ r5 s: m6 D0 C//cEnable: "event.rc= true;" } );" ^, P: }/ ]8 `% N( D9 v2 y
app.addMenuItem( ...{
! J t1 Q' B% B: A* Y' |cName: "删除一个书签(&D)",7 u( a5 k( R8 \- ^3 ?. i6 h; r
cParent: "View",
' n! i- s: V" Y8 |" XcExec: "DropBookmark();",
. h. N6 W- }7 xcEnable: "event.rc= (event.target != null);" } );
& r+ S4 u+ Z' i7 L( T a8 o& P5 G2 mapp.addMenuItem( ...{
0 t6 [( R: @% O0 e2 S3 y, a I: NcName: "清除所有书签(&C)",; V: G) l1 B/ R$ Z- b+ C$ q
cParent: "View",- o; b, X5 q& `% w# \
cExec: "ClearBookmarks();",1 A+ w( J8 w6 z9 Q8 P e
cEnable: "event.rc= true;" } );
f7 ]) s4 D( p) [" W4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
; X& T9 x {% m1 l& G5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了5 I1 I2 B& P* n& l$ _
8 z8 W1 q4 k, v6 m8 {5 z
2 t, a; _9 r9 J' O5 k本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|