TA的每日心情 | 奋斗 3 天前 |
---|
签到天数: 2383 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
1 O5 y* |- U3 U( [7 Y1、打开编辑的首选项项
4 ]: r K( w$ o4 p- V" I% h$ y
: P7 q7 r1 {8 q Y2、确保下面的选项都被选中
9 D9 X2 }' t) v4 e
( r# C8 ?$ K/ ?/ t7 _6 \3 把下面的代码保存为一个bookmark_page.js文件# h' |# r; K6 D2 R
// bookmark_page.js, ver. 1.0# |* q- ?( W5 e
// visit: www.pdfhacks.com/bookmark_page/5 I5 l! ~, j) W/ H8 P
// edit:cjs 2008-02-17
) ^8 o$ A6 ?0 m P// 1 修改为中文标签
# a1 {+ U4 k& Z& F2 b// 2 设置书签时可以自动获取当前的书名
$ G5 ~* c9 p# b// 3 自动获取当前所在的页码与总页数,方便查阅
: l7 f% e8 h: r/ \" m; r" j// 4 实现更多功能可以参看Adobe Reader的SDK' z- [, Y% s. g# |8 q3 ?
/ T* z: S! W( Z1 n1 @/ j5 F// use this delimiter for serializing our array" A) I6 m6 ^" x3 Y3 k' Q) }
var bp_delim= '%#%#';
- v, G( v* X- d. sfunction SaveData( data ) ...{
5 H( a! Z) T" U$ N! J // data is an array of arrays that needs
8 r6 z4 H( ^1 w* Z: K! S& }1 I/ S // to be serialized and stored into a persistent
4 W) i+ t; M1 o" Z; m7 ^ // global string) l! e& x7 S! c0 \" W- U4 r1 g. k
var ds= '';4 D! o+ |( f O) L
for( ii= 0; ii< data.length; ++ii ) ...{, u0 F; Q" x' M$ ]' P9 }
for( jj= 0; jj< 3; ++jj ) ...{
( N$ u/ f$ {* q. c& p+ B: @ if( ii!= 0 || jj!= 0 ), N9 T" d7 G/ e7 d _
ds+= bp_delim;; y0 e$ V# y d( u& k/ @
ds+= data[ii][jj];6 O6 ]. ?3 g6 }: e: T, G( F% w
}
z. m9 i! Q; E6 Q) x: U7 Q+ c! ^ }
8 [+ W9 O7 J2 |# a/ q global.pdf_hacks_js_bookmarks= ds;
. P; G3 ~' d2 M3 K global.setPersistent( "pdf_hacks_js_bookmarks", true );
1 G( U5 A- [: _3 h% Y}. u% S0 D& n# w2 Q/ Z" o
function GetData() ...{% b& q# P& o- @& P6 w) n$ a
// reverse of SaveData; return an array of arrays
# v* r& w! Q+ ]5 V if( global.pdf_hacks_js_bookmarks== null ) ...{
5 z5 o: S/ K- `! o3 n return new Array(0);
. j' C/ d- m% J/ E9 } }1 j4 q6 f" c0 i
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
6 ]6 T' K8 l; ?4 v$ |! `: w var data= new Array();+ E) x5 C8 R1 d& i O) P/ p
for( ii= 0; ii< flat.length; ) ...{
9 R3 c, d F# I: q* g, z) s var record= new Array();
- B: v* P* K8 l( ]1 `, Z for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{; j1 I7 k: {; w" p: l# {$ J
record.push( flat[ii] );
5 f* @- I* v1 l1 l% T% O }1 b% M5 N" h/ z) [# N1 p
if( record.length== 3 ) ...{; q9 y# {) s4 d$ |. B Y
data.push( record );
, x. }. a. l! F, P }# @1 L8 v6 P" L
}
: h; L* {9 D6 U1 b9 q2 N return data;
9 Q2 P4 o7 F: ~}
) }6 I$ W6 A7 V0 i//Get Current Date
' n0 ?) f) r* }9 l" O6 e! U P; T" Tfunction DateNow()...{9 |- W: m8 ]( \
var d, s ;
: Z: @7 v6 t. i, ^: P d = new Date();3 P" { E- Y5 n
s = d.getFullYear()+"/";, L4 [+ Q6 q( N3 m, ]7 G
s += (d.getMonth() + 1) + "/";
6 d0 u6 s( U I% t7 V. M2 \ s += d.getDate() ;% Z3 l. _- L; D, p' ~ z, K
/**//*
3 U9 |0 z8 l$ y$ L0 i* E, | s += d.getHours() + ":";
5 f2 r* Z* @+ a/ [2 [. a s += d.getMinutes() + ":";) u- g+ S5 G! l c1 E6 k
s += d.getSeconds() ;8 X' A7 j, \) f# z% b( E
*/
n; g# w: h& E- s return(s);6 _. s- m" h; t0 u4 y8 q/ G
}
$ \! C" B" B) ~" ], Q" C/ T' `( q2 u: X
function AddBookmark() ...{; e; v+ R& i, t
// query the user for a name, and then combine it with
; v! J& r9 i; n. s& U! @5 [ // the current PDF page to create a record; store this record4 M! x) q) s0 g- y1 C' P9 y% j
var thisfilename=this.documentFileName;* ^7 }6 y" z- F6 ?8 q) z8 Q
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));: M8 x" q& n; J
var numPlugInss=this.pageNum+1;2 K& O8 Y/ V5 b' U* u
var currentdate=DateNow();2 R0 d1 S$ \ j1 {8 @% `+ ^3 Z
var label=
4 E/ ^% i& l; _4 {. E app.response( "书签名称,可以修改以便于记忆:",: j5 K, z3 R* B6 O8 {
"书签名称",
9 r' g7 ^! c" l% k7 @9 b/ N "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
6 M; w$ ?3 T+ L& ~ false );
' z! X0 p, a% Q+ ^0 P/ o if( label!= null ) ...{
3 V. L: w! `4 I) @0 |, V% N var record= new Array(3);
* z9 t4 |+ ^% O4 w% u7 k& L record[0]= label;
- @/ S) V2 v! ? o. E record[1]= this.path;! b2 [8 c2 |$ X. e
record[2]= this.pageNum;
6 s' p7 j9 _8 W; d data= GetData();: _8 J! R, g% w% [ ^
data.push( record );
1 W, ]( i& ? M! ^5 F SaveData( data );
. X* d& p' p* ^/ G }' I7 p" |: S8 k3 A) r! g; ~
} \- L: b9 C/ r" _8 W
function ShowBookmarks() ...{& {. f# Y6 N3 E- m$ F1 N3 k
// show a pop-up menu; this seems to only work when) d% }! s; h! p- X. I" n
// a PDF is alreay in the viewer;
1 g' o n4 o: D F$ k1 C3 D) ? var data= GetData();+ w) e1 s: N5 Y1 F5 D ~: `' Z: g
var items= '';
$ V' r8 T6 r6 `' } for( ii= 0; ii< data.length; ++ii ) ...{
0 `3 z9 O0 q/ g; E( P1 I if( ii!= 0 )
) {9 V+ w3 o9 O2 K# T; p$ T items+= ', ';, O6 I, r* m3 I+ L$ d9 x
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';+ C+ E$ f- x9 g, X6 ]
}
/ U8 N+ ?7 q: z, c! n! L5 \ // assemble the command and the execute it with eval()
2 b8 x7 X, u& Q/ T7 Y var command= 'app.popUpMenu( '+ items+ ' );';
5 y9 J$ h6 t% Y( Y1 o3 W var selection= eval( command );/ @" K: _* b' y; y/ w O* i/ N
if( selection== null ) ...{1 J L' y! ~! F
return; // exit g$ t2 s: h2 O9 ]
}
4 Y+ M8 M s9 r( E' p7 o9 j // the user made a selection; parse out its index and use it
+ P. _2 j, E$ _# E5 p+ g // to access the bookmark record
- I$ @$ t; \4 P2 P9 v$ z var index= 0;+ h; x- ~ }2 F; p2 ~% ]
// toString() converts the String object to a string literal' c) A7 |3 H9 Y) Q6 d
// eval() converts the string literal to a number- ^+ H0 ^) z( V( v5 j R P
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );" v9 P% R; d7 x
if( index< data.length ) ...{( @. J8 f7 |5 c& ^ b6 e
try ...{
2 K5 I2 z) Q3 B, D // the document must be 'disclosed' for us to have any access8 ^) J6 w) }& E, m8 y& [% a4 a
// to its properties, so we use these FirstPage NextPage calls
6 X9 w0 i/ }/ Q; n% ^6 n3 M- l, w/ _, A //
* k, u& P6 g2 O# I5 q4 ^) f app.openDoc( data[index][1] );
2 @* C2 m/ S, p# D- O; [+ e app.execMenuItem( "FirstPage" );8 ]9 z4 H& `- q7 E0 r/ I
for( ii= 0; ii< data[index][2]; ++ii ) ...{' [; [/ k: r3 D
app.execMenuItem( "NextPage" );
& A* E. I2 y4 ]5 T8 t( k }
( P ?; \1 P; s- ` I }& t6 ~. q, _4 N7 A9 w, g: h
catch( ee ) ...{
7 h, P( s+ ^6 c- Y3 Y+ I V5 R var response=
_9 @5 M8 c6 x; f2 o app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");- l5 \5 c: s) \8 k* I
if( response== 4 && index< data.length ) ...{
2 |/ l! ^: w/ z" ?5 K& X( w data.splice( index, 1 );$ i2 U' A6 S8 _' Z$ f
SaveData( data );
2 `$ t5 g8 ~" ? }$ \% R3 A( q% k: K6 b
}' M/ ]8 r4 C6 L- M/ C
}
4 Z, w: Y& _/ o}" f9 e- b9 i3 T% z& U* F6 }
function DropBookmark() ...{
% J0 k8 p8 U( a6 J# J' E // modelled after ShowBookmarks()1 T8 M8 ~5 s2 L9 l7 P, ~( c1 O
var data= GetData();
7 F' S& U) Q/ F/ j, g4 f! r var items= '';
5 Q2 {, @2 ]- ^, d for( ii= 0; ii< data.length; ++ii ) ...{) r' f! U, d+ q! p9 } N- K
if( ii!= 0 )0 R4 F) g$ Q' i3 y8 @4 ~! b! D
items+= ', ';
' v0 o6 r1 i5 @8 A2 B items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
: M2 `( c7 C4 d2 v9 }, c |) } }
& v% ]" E& H' e9 o4 Y( H0 g var command= 'app.popUpMenu( '+ items+ ' );';, |: g9 F" S, d/ J( z i: v$ H
var selection= eval( command );: {$ q( W7 [( k4 R
if( selection== null ) ...{) I" L: J4 d# }6 T: Y
return; // exit; o6 R8 c3 }: R, ~- J& J; k
}# o% k0 F/ e; b7 m. r$ X
var index= 0;( Q6 ]8 _. d2 L1 o* o
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );9 T+ y) c `/ F
if( index< data.length ) ...{& x2 O7 @# D0 c* K9 e& J/ L
data.splice( index, 1 );' ^( c3 o+ b. Z, f# U
SaveData( data );0 b- F/ F) J7 R5 ^" L6 f U: M- T" N
}& G; A0 i2 t" O$ e, P$ I5 [% w: a
}
: R* S% W! ~6 Bfunction ClearBookmarks() ...{% e( j" B/ r) U5 u( z, m
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{* j1 L/ Y, p8 h y3 s: E
SaveData( new Array(0) );
. F# P. T. f6 j" p }
4 _/ S T$ g9 e- t! x7 ]3 F}" @. E3 J9 { e1 z5 O
app.addMenuItem( ...{/ c0 y4 i* O$ z% _
cName: "-", // menu divider( ?0 ]6 W3 h' q% t
cParent: "View", // append to the View menu4 g- }/ i5 I1 M1 v
cExec: "void(0);" } );( v: r% u% i: a
app.addMenuItem( ...{
! }0 H' x6 X5 F2 X8 |& q. |8 H5 CcName: "设置本页为书签(&B)",
( n+ x! ~; i/ O6 c( c! I5 acParent: "View",
6 D& `8 F6 g1 F5 _; @# D! PcExec: "AddBookmark();",. Q5 y* f2 |2 @1 V/ t
cEnable: "event.rc= (event.target != null);" } );
0 G* t( Y8 N q- Aapp.addMenuItem( ...{
" g" [6 c% M! b' G; X$ YcName: "转到指定书签(&T)",0 j" c* n9 n3 c& b: ^* y6 d
cParent: "View",
8 r0 i9 p1 Q' kcExec: "ShowBookmarks();",
. Y; d( c8 K' D. gcEnable: "event.rc= (event.target != null);" } );( Q7 b( t8 L5 ^& [* \
//cEnable: "event.rc= true;" } );. {; \. f; H; F D
app.addMenuItem( ...{
# Y$ w3 c4 @7 W3 o# fcName: "删除一个书签(&D)",/ A) p) m# G/ j- }1 A
cParent: "View",
( M5 ^8 D- M' d$ Y- z" XcExec: "DropBookmark();",0 t6 q2 `# c5 @* q* H
cEnable: "event.rc= (event.target != null);" } );) a: e2 K# z3 a. k7 R: a* h
app.addMenuItem( ...{
4 g! b, G; K0 v5 G# d B; zcName: "清除所有书签(&C)",
6 h" Y7 i! P8 k+ [2 ~4 C& NcParent: "View",2 N* d/ K1 F3 |( ?" B
cExec: "ClearBookmarks();",
# q; ^) V5 M; W N) R# ccEnable: "event.rc= true;" } );3 D1 K7 w% h1 ? m
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下' g* a& V' I- Y6 J x
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了! y" p1 \# I, B
$ q/ F8 U% k) H& z N* R/ X j- [, s3 `9 _6 V/ C5 p
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|