TA的每日心情 | 奋斗 前天 10:28 |
---|
签到天数: 2370 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法5 m* Y# ~- S& V4 X3 O1 I3 z
1、打开编辑的首选项项
# w1 t5 o6 r( ^( \5 E: a5 |/ ~, A1 E: D
2、确保下面的选项都被选中 _' ^% H; X% U* J0 }
; ^! w$ c6 H) ?! `3 u) i$ Z3 把下面的代码保存为一个bookmark_page.js文件
# b7 N5 d# }! y& ?// bookmark_page.js, ver. 1.06 J4 J0 n3 s5 c7 V) @0 R3 Z% a( Y
// visit: www.pdfhacks.com/bookmark_page/
& S9 ~' Z8 V: _+ Z// edit:cjs 2008-02-17
. t& Z3 L3 t; j7 y: g// 1 修改为中文标签! p0 L/ N. [8 c7 J
// 2 设置书签时可以自动获取当前的书名
5 }7 J/ q$ R k4 H( A$ n// 3 自动获取当前所在的页码与总页数,方便查阅
* B$ I$ r3 }: ~- S; _& o" x// 4 实现更多功能可以参看Adobe Reader的SDK
* a3 m9 |( r* E5 M- ]1 P' I3 ?7 G4 w5 y
// use this delimiter for serializing our array" {; N; v/ m$ Z- `4 l, O) @% N4 Z5 }
var bp_delim= '%#%#';0 r0 w3 ^( G% j
function SaveData( data ) ...{7 m: J* K( a9 g6 C
// data is an array of arrays that needs2 Q' J* i. F$ h1 m
// to be serialized and stored into a persistent; G2 F: w- |9 w
// global string" P3 @7 X6 j# u! @! y4 h. \
var ds= ''; o* l ]8 g/ ^; C4 z. h6 X
for( ii= 0; ii< data.length; ++ii ) ...{( v2 I6 k, i! h" c9 U! P
for( jj= 0; jj< 3; ++jj ) ...{
1 w$ f. _. P, f; [. i if( ii!= 0 || jj!= 0 )
3 ~" r! `1 x( Q' T) p ds+= bp_delim;
6 s5 [, ?: ?8 }! C2 y* w) ? ds+= data[ii][jj];9 S) I% Q4 o, x& q) k% P
}
3 P$ X1 x! ]9 e% l3 O }& E3 a* K. E2 I
global.pdf_hacks_js_bookmarks= ds;
2 S9 D/ v- M" X( @5 c1 h global.setPersistent( "pdf_hacks_js_bookmarks", true );
: i6 v6 y0 l. [3 a& {% H}
9 r. Y" E) g. x: D* Ufunction GetData() ...{
& f5 H' s, ?: R& M) I7 Q/ ~ // reverse of SaveData; return an array of arrays
$ u6 H2 w0 U) [- S( t if( global.pdf_hacks_js_bookmarks== null ) ...{
" J5 n& f3 b; e return new Array(0);, O0 L, ]* c4 {0 o
}
" w) C5 s/ @4 @4 y7 u8 L1 o, ^4 H var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );- p, C; |4 a' q7 S
var data= new Array();: X, W( i1 R3 V6 `, {3 Z4 z2 B( w
for( ii= 0; ii< flat.length; ) ...{) H! Q$ o) g4 v1 ]4 o% d' z
var record= new Array();* P8 |, s( i# J5 u r
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{2 r- ~3 h, R3 f
record.push( flat[ii] );4 K; ]' B! ~* f" [3 v% t, b L
}. B) U! F H Z4 n4 b
if( record.length== 3 ) ...{$ [7 t; [; L0 f) l
data.push( record );8 j5 b6 ]$ g: s! c* ~5 M4 u$ h
}0 f' @; |& R* _, v* r9 @
}1 z( {9 O8 U$ P' r( T9 C
return data;
- J; S3 T# [7 m8 z}& [: [- r# d2 b8 A
//Get Current Date1 d' v2 C# G/ v3 C/ x9 S/ a- `
function DateNow()...{
+ l; r) X' t2 D* p var d, s ;
8 f0 [* P4 d) U! z4 p3 H d = new Date(); Q a/ k' y/ Z4 v
s = d.getFullYear()+"/";; C- J, u. [' j W
s += (d.getMonth() + 1) + "/";
) B/ ]( V$ j5 i! r- r0 ^% b" [ s += d.getDate() ;1 u7 z" m8 ?; R% a
/**//*
8 \8 i" m/ x9 P4 o2 B s += d.getHours() + ":";
- N3 X0 A3 W; _+ ^ s += d.getMinutes() + ":";
+ e# q1 _9 i, b( y& F. i3 O s += d.getSeconds() ;3 D9 N) L+ [: ^. n( v
*/ C) z3 f. o; _) ], S( ~. x2 s, z
return(s);: [: D2 u# q3 c, c* u# @5 j
}
+ d6 q2 y( y6 d7 p# X2 D, T r) j8 ]# Z4 N$ p* b& D
function AddBookmark() ...{7 w9 J+ Z' {& o; S1 z$ b/ s
// query the user for a name, and then combine it with
, ]/ A- O/ @6 J/ T // the current PDF page to create a record; store this record& `9 n! l9 c' w7 ~' S
var thisfilename=this.documentFileName;& z6 ~- f3 z. E* I* g
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));0 s. f' |5 f* z
var numPlugInss=this.pageNum+1;
, E& L! U, A, M3 b3 z& t var currentdate=DateNow();
. S! H' k) a$ `' f3 H4 U var label=
$ q1 }2 u. B2 b1 E8 u app.response( "书签名称,可以修改以便于记忆:",: Z% D$ |% I9 j7 ^4 I+ \
"书签名称",9 I0 q; Q% G$ v) F( Y- s
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,% w0 C1 ~. a w: i
false );
8 [( Z1 M3 B1 x& ~. e7 i/ o if( label!= null ) ...{. d: ^- k+ F4 U3 ^- P
var record= new Array(3);
+ ^/ H( ]9 \$ n, }% o5 w record[0]= label;' o0 F, D! [) ^- M& _
record[1]= this.path;
) T) E9 w1 D# y- q) G4 i record[2]= this.pageNum;. Q# S+ A# N9 X+ k: \. K- N
data= GetData();7 K, G# e$ j. p6 c! S# N% d) x
data.push( record );
7 z$ a+ Z. h, I! Q3 } SaveData( data );/ l5 m5 H8 P: |7 h
}
1 p, k' Y8 W _+ G( E! U}
! R4 w8 A4 y4 d" [4 Pfunction ShowBookmarks() ...{
( R, P- B( A5 F q8 n1 D // show a pop-up menu; this seems to only work when
( Z) [3 }8 }6 D$ N1 ]& d& M/ M0 ` // a PDF is alreay in the viewer;, K' h, M2 s3 J
var data= GetData();
% V0 M* e' v% N/ f% p0 v var items= '';: ~, c( a( \3 C! N- I; P% E# s% B
for( ii= 0; ii< data.length; ++ii ) ...{
/ t4 `" J4 _+ K6 f% i U" c: [ if( ii!= 0 )
( d; [. F, n/ Z3 c f8 v5 T4 S items+= ', ';# ^5 H7 q- x& n( y9 k8 \+ d( i
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';+ B. y3 e8 o5 |* K; q
}0 w5 ]3 S1 b# b: d4 ]
// assemble the command and the execute it with eval()7 w* R ?% Z6 O6 m4 [
var command= 'app.popUpMenu( '+ items+ ' );';; X% i3 A% Z" L
var selection= eval( command );
9 n! V5 _$ i/ j7 Q- r if( selection== null ) ...{+ q% s6 H& r! k$ P ~
return; // exit
( t$ p' Y8 h- U' b* j- d }
5 y6 j# q1 W# U! V* ? // the user made a selection; parse out its index and use it
0 |, Z7 }" E. }- n" i // to access the bookmark record
4 t+ j0 c$ Z4 R6 m var index= 0;: k/ c8 f$ p# ]8 Z) R" i
// toString() converts the String object to a string literal
! k' `% S$ m& G // eval() converts the string literal to a number
P* B% N% J% k8 K1 T2 W index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );* g9 B3 E( n! {2 N) r/ V2 y+ X
if( index< data.length ) ...{% d4 K. Z% r! Q, y( P$ R
try ...{1 ?4 h4 f1 O! }- s$ _; ? ~' U
// the document must be 'disclosed' for us to have any access4 M K8 J4 Q* c) Q
// to its properties, so we use these FirstPage NextPage calls
% u" X# E6 ]/ _- i4 c0 y+ ?8 l( J //8 j- S \% L) r* r4 ?% u
app.openDoc( data[index][1] );
5 n2 r7 x) l, ~( S% v! A& f app.execMenuItem( "FirstPage" );" v8 r5 b. h$ x; k
for( ii= 0; ii< data[index][2]; ++ii ) ...{, e& J& ?$ x. ^+ @1 i: [
app.execMenuItem( "NextPage" );
5 m# {- {$ K- l2 N" h) ^' r }
4 ^: W6 d" M% s4 X }1 W# m& }5 w0 y9 k! s- b
catch( ee ) ...{8 u1 x5 m7 E1 u! R
var response= - b8 z8 r) J$ H+ C
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");: j# |- U5 d! Q8 _' l( q' Q
if( response== 4 && index< data.length ) ...{# a/ x$ \6 @7 ?- P( v- q
data.splice( index, 1 ); ]1 ?0 S4 { v+ O
SaveData( data );
& |- z9 ]1 n$ j. X3 _ }& g7 k& |7 a5 A. Q6 y
}
* i6 Q) l" Q$ T }
j3 D5 r- `5 }* F4 m8 f}
) z* J: v: t: nfunction DropBookmark() ...{1 y7 ^( f: }4 F: q$ L
// modelled after ShowBookmarks()! |" m0 u n* d. n
var data= GetData();
$ r: h* ?6 |5 f var items= '';0 H# h9 \# Z1 o& C8 u) _7 A% C8 W, U( R
for( ii= 0; ii< data.length; ++ii ) ...{
" s$ W- C/ w5 B. H9 g. D' w if( ii!= 0 )
/ o2 T6 u& J8 d) s+ N items+= ', ';
7 f. O$ b+ W/ @2 S items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
+ N. P5 G" p2 s0 c( m+ c- r2 S* o }
$ Z _+ i: ?* }) ]$ K6 H var command= 'app.popUpMenu( '+ items+ ' );';* a6 y4 b) ~5 J$ a% }& G
var selection= eval( command );# F. \" H" m7 S, g
if( selection== null ) ...{# ]$ ], ?! k0 E6 ]! ?
return; // exit
2 l& Q7 J8 V \" y- H }4 U* m" C3 {0 `6 }' j" U/ [4 k
var index= 0;5 K6 J. i" {( R0 C. l a3 d
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );" s4 W- D7 A, V2 w- D3 v
if( index< data.length ) ...{% ]4 i5 Q/ z2 C2 t( H- I* [
data.splice( index, 1 );
t0 \4 |5 W/ P* e8 S1 | SaveData( data );
( U: Y6 p( K: F, _ }3 s) q3 [4 {( G6 C9 A- L) M
}
5 J* |, \3 d: v; K4 G8 e- sfunction ClearBookmarks() ...{
8 O* A' i) Z/ Z2 s' W( p- @: ? if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{* q; J* N8 i4 F9 H0 @$ ^9 G
SaveData( new Array(0) );1 t! M% A3 }# G9 |, r
}- s' d l" s$ P( ^
}
+ M, }; \1 t# m; Gapp.addMenuItem( ...{; u4 a% t! u5 a& E7 j4 S9 A
cName: "-", // menu divider! l, v2 N1 o7 g4 v$ p4 {* T
cParent: "View", // append to the View menu
8 o/ l0 M: @2 {% R1 j- f9 HcExec: "void(0);" } );. X8 v/ |* x) N+ Y( c( V" T
app.addMenuItem( ...{
J' m, V! p+ m+ fcName: "设置本页为书签(&B)",
, d( ^) O0 C+ _$ `cParent: "View",- I1 t0 b e4 Z: k8 _
cExec: "AddBookmark();",! T, ]! o$ @1 Y" s/ ]
cEnable: "event.rc= (event.target != null);" } );
( M; B) ^* Y& B Uapp.addMenuItem( ...{& y' r" }. A3 [0 W( Q
cName: "转到指定书签(&T)",
0 f/ N" ^8 ^9 ?) bcParent: "View",
! Y1 y+ b7 Z: U" l7 Y: F6 W) BcExec: "ShowBookmarks();",7 U( R7 h" F! }$ s. h% a# X
cEnable: "event.rc= (event.target != null);" } );2 A2 r9 P- r# a1 o" V2 f0 K
//cEnable: "event.rc= true;" } );$ Y+ n% s* k; {/ ]: r, A r
app.addMenuItem( ...{6 t; V) [) }- ^) T9 v: f
cName: "删除一个书签(&D)",$ e; Y; |0 ~, A1 x4 @# P
cParent: "View",
- v m% C, G" DcExec: "DropBookmark();",
+ [; }/ f5 Q( B$ mcEnable: "event.rc= (event.target != null);" } );1 k0 K& W! e1 g1 ?1 X" B
app.addMenuItem( ...{
~! R6 h0 o5 I2 R& l* Q; RcName: "清除所有书签(&C)",
. r/ l& i- {- h6 Z2 ~cParent: "View",3 ~/ ]" m) M- i! \
cExec: "ClearBookmarks();",2 @! q V1 a0 _, U3 b8 ?
cEnable: "event.rc= true;" } );
W/ V/ i4 T8 j3 O, m4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下( D" E0 \$ F2 C- R: n
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
- Z7 y g* f: S y+ K8 J z
1 u- y, I3 v- x. ]1 k* `
% o8 v) r2 b2 s- o2 W本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|