TA的每日心情 | 奋斗 昨天 09:03 |
---|
签到天数: 2400 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法$ j+ a) m( c$ K+ G# T6 J
1、打开编辑的首选项项
. p8 f$ ^, |& f" m/ ]
4 M6 t/ y+ Z& Q5 k0 | {4 @3 j2、确保下面的选项都被选中% u, |7 c4 X1 B, b7 f7 [
, g7 J# N( M( t% J5 |5 ~ J: q3 把下面的代码保存为一个bookmark_page.js文件3 W* X: j% E$ r7 L5 d$ \, P
// bookmark_page.js, ver. 1.0& O3 _# ]1 s2 q( I5 {8 |
// visit: www.pdfhacks.com/bookmark_page/# F% O: ^! S+ T; r. \" k( v
// edit:cjs 2008-02-17 $ o+ c; y8 q0 b; T
// 1 修改为中文标签7 _- E2 B- t [, J* [7 \) M; v* e
// 2 设置书签时可以自动获取当前的书名
8 \1 D3 J8 L0 Q3 L9 f// 3 自动获取当前所在的页码与总页数,方便查阅
0 e Q# \5 n( U1 t: _. T// 4 实现更多功能可以参看Adobe Reader的SDK8 s: r3 Z8 k' N/ Z, S" m! G
3 F1 d- O) ]! n. ^# I' }# x// use this delimiter for serializing our array
; F+ Y; l0 A, ^* w# Q& Tvar bp_delim= '%#%#';) ^7 a) k8 a* G9 D' w
function SaveData( data ) ...{
. |6 h* y8 f, J5 B3 m$ z // data is an array of arrays that needs
: U; [- [ p# \* R! [# \, ? // to be serialized and stored into a persistent
" V" V ^% e6 C+ c! ^2 N // global string( \: n D) ?9 e8 [2 f
var ds= '';# b8 u! x! E' J& }7 F5 D* L
for( ii= 0; ii< data.length; ++ii ) ...{2 F( L% C! I) O: b
for( jj= 0; jj< 3; ++jj ) ...{, ^, j2 R* j) O( X
if( ii!= 0 || jj!= 0 )3 H3 g% @# y$ Y6 X6 u6 r$ f3 O3 q
ds+= bp_delim;6 n; c, w( O- a9 r9 _. g/ W
ds+= data[ii][jj];
- u1 D( I$ n) { Q' Z }' o9 @- }0 F9 N' d: w
}
5 z6 ` X' G) ~' z7 x global.pdf_hacks_js_bookmarks= ds;- T2 a. v5 o5 j& E1 E7 Y9 t1 c
global.setPersistent( "pdf_hacks_js_bookmarks", true );
0 e! d. D* V, i5 } E# m}5 V! \3 [/ m$ I; F
function GetData() ...{
9 V6 A: E" g4 K' V& v // reverse of SaveData; return an array of arrays
/ S" R) C4 D5 ]% n if( global.pdf_hacks_js_bookmarks== null ) ...{% I8 }3 E7 h' ]- s, Y
return new Array(0);
" J* [: b. s3 I0 q }
! T6 S2 @& y9 r9 [0 o var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );4 a7 _# M6 N5 Z3 f. v% i
var data= new Array();2 |( y3 `8 Z# C7 [! A* j1 F' Z
for( ii= 0; ii< flat.length; ) ...{. ^8 ^, y$ S9 k/ O& e
var record= new Array();
) A6 W' H5 o+ a( ?9 ?- W3 e3 l; _ for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{/ T, w4 _7 {" M% @2 W
record.push( flat[ii] );" A3 n1 F9 R* z! ]; C2 Y5 B
}
: i( G% l+ W/ f+ `$ `/ L if( record.length== 3 ) ...{: ]: e: S6 O( k5 Q' ~
data.push( record );
+ n4 Y: X2 L" z) a }
( ], j, {& e" J }
, X1 [6 c6 e2 n& q$ K return data;
. u! N0 L& @) _( l1 N6 W0 O}
8 K& j6 J$ \; ~/ x//Get Current Date
6 U3 t/ R: v( ~' D, j$ Wfunction DateNow()...{
: ^8 S3 _' t8 F% g5 R: h var d, s ;. v' {" Y/ {. `' D
d = new Date();- ] e" V/ k5 S% P" e
s = d.getFullYear()+"/";; `( p+ z( T" O! l0 z# x
s += (d.getMonth() + 1) + "/";
: e; i; L' X6 p s += d.getDate() ;4 i2 Z! W2 F5 z# |9 e# o5 D8 V
/**//*( U. f. k( m% w6 Z {8 | {7 Q
s += d.getHours() + ":";
3 B6 B' L4 s x3 ~3 a6 y0 J% ^6 K s += d.getMinutes() + ":";
/ r' y/ _# a, O1 v: |% @( n s += d.getSeconds() ;
: u* C% q1 G, a */9 K! s6 W& [- O" _2 e
return(s);8 C# ]8 f& \2 X( F! M
}: {) t/ q( S2 ]& r
* Y- U' o: l. Z, P, u( w# e9 N: ^
function AddBookmark() ...{8 e( m: U+ m8 h
// query the user for a name, and then combine it with" D% d! H t( ^
// the current PDF page to create a record; store this record5 J0 q$ c: i7 U* x1 ?$ i# E" V) i
var thisfilename=this.documentFileName;* ~: g& @4 g' g4 J7 c
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
3 d( `7 R5 S. Q% X y7 P! _ var numPlugInss=this.pageNum+1;
1 E( _# O6 ?; {$ J. L1 e var currentdate=DateNow();2 n& O. O& b/ U. l& A3 F) _
var label= : C/ `: {4 R0 S, Y Q' `9 ?) c
app.response( "书签名称,可以修改以便于记忆:",
+ }& E; s* {2 O+ l6 ^5 N5 @ "书签名称",
3 ]9 Y7 s' {% x6 D4 {& g "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
$ C6 ]5 w: t; H: d! ~- n false );
$ ^2 |) s- w! w4 M if( label!= null ) ...{
. V u3 C' U1 a8 n/ B( O var record= new Array(3);, g8 I! q2 e* N# v4 j
record[0]= label;
; T. y3 {8 z* q9 ~( M record[1]= this.path;0 v* P8 j3 c& j$ V
record[2]= this.pageNum;
9 j! g* n+ M5 T5 U9 i data= GetData();
: K+ Y# z. H* S% s# h data.push( record );
) g+ n3 s4 X: {+ V6 Z SaveData( data );+ i7 g/ ]& l! k7 P2 V: f
}
+ y- M; X( h9 I; @, C; R3 B}7 K2 a0 ?- q f+ z8 X3 W2 h
function ShowBookmarks() ...{
/ q5 D! c7 K+ Q // show a pop-up menu; this seems to only work when
, T: Y3 f) f) V9 J" m // a PDF is alreay in the viewer;
' l! f1 e2 l" } var data= GetData();0 k# ^8 j [# i4 e5 `; q
var items= '';- `- h% \ E* p" A3 u: w) {
for( ii= 0; ii< data.length; ++ii ) ...{, W: l; j8 D+ }
if( ii!= 0 )
3 P* Y6 e+ q; K4 e8 F6 c. G/ s items+= ', ';1 Y. y5 j3 c3 p8 K' }) h- G
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';4 E& p7 M6 O' B' ~
}
& P5 c6 {' {; G$ ?* d6 W3 {+ F g t // assemble the command and the execute it with eval()( U6 Z, h# u3 c
var command= 'app.popUpMenu( '+ items+ ' );';
% U* ~- v( h& r' m var selection= eval( command );
) g2 n$ I& S! L# R; Y! b0 O if( selection== null ) ...{
5 |1 W% M8 c9 r return; // exit& F; [. L+ i) E; W
}5 D4 E* ]+ {/ e% _
// the user made a selection; parse out its index and use it- N8 R+ T1 O5 B$ w5 ]7 H3 _
// to access the bookmark record
( a6 n. y8 m$ X5 P8 e$ `! n var index= 0;
$ }* M- t. U& X& b6 u, K6 h // toString() converts the String object to a string literal
7 \% }6 ]! }4 E5 s) g, ? // eval() converts the string literal to a number
4 J& C& L2 I3 k1 S index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );% g% z& Y( N" u: W
if( index< data.length ) ...{3 ~6 m$ ~9 e3 p5 y* [
try ...{( {1 I$ K: [2 y+ S
// the document must be 'disclosed' for us to have any access
2 g$ h1 N$ H8 O, m // to its properties, so we use these FirstPage NextPage calls1 h" I& Q1 J( M2 K, s
//
! n/ q! r( x# J3 \6 e8 v6 w app.openDoc( data[index][1] );, g2 e1 }( c2 [0 U
app.execMenuItem( "FirstPage" );
1 x# J) W8 c5 |" ]' h/ [ for( ii= 0; ii< data[index][2]; ++ii ) ...{
7 L& V; p7 o2 z3 o1 @ app.execMenuItem( "NextPage" );$ Y( \/ o) s3 A: c
}6 L2 P Y* b }2 p# l
}) s6 C9 a5 c6 v6 s( L& O
catch( ee ) ...{
( t2 J2 q: b$ H' `5 l" J9 c var response= : L/ j3 }6 \ K" D& j
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");. g. K1 B8 k V' _& `6 j
if( response== 4 && index< data.length ) ...{- J7 f1 G0 s6 S& Y& c) I( P
data.splice( index, 1 );3 i, @3 r- h$ e$ x/ k- [
SaveData( data );
9 w/ X) A, Z* K2 v }0 ~- U/ g8 |6 a0 J) Y
}
( Q! p* P: S* q% f$ Z; Q }* S' Z4 [, o$ S3 n
}
+ E n) r* }2 @8 x9 q5 Hfunction DropBookmark() ...{5 g: F9 \. s1 ?7 Q" d: ?4 k
// modelled after ShowBookmarks()9 n0 m Q0 N% c9 `% l; }
var data= GetData();& K# }% [5 D8 ]' H- L! I8 P) B: |
var items= '';
- M5 l: D! [0 X8 t for( ii= 0; ii< data.length; ++ii ) ...{
' I! q+ |' v1 J2 f: r if( ii!= 0 ). d: V5 ^" [( a1 H
items+= ', ';6 o. {1 g8 s' N: {1 q- L$ W- N1 X
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
5 g% G3 F+ r0 {6 ? }% v/ Q* O5 r5 r _! L) B+ H2 C+ @
var command= 'app.popUpMenu( '+ items+ ' );';' E0 _; h5 q, y& U: t3 r% j" k, z
var selection= eval( command );
U4 C! [; F; _ if( selection== null ) ...{; @& {; U' D4 z+ c* P5 N, B
return; // exit
. L! V) l* K0 R" s) D: Q }
* x4 d% T. w7 }, U7 x7 Q! v7 [ var index= 0;
5 ^& k( q+ ?1 Q: O index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );/ e& M" L3 V. X" n* x4 ]/ b
if( index< data.length ) ...{
0 [% x# r, Y7 Y' f data.splice( index, 1 );
# z- q1 c4 m C$ ` SaveData( data );
5 w. ]: ?, t* f, Z% M9 z _' ~ }
0 d9 x1 e. m2 K/ p9 [% e2 I}
r8 Q- q2 H. g6 z* S" Ffunction ClearBookmarks() ...{3 w/ b) l! N3 h, w/ n
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{4 P. p# w/ {( y6 J- V
SaveData( new Array(0) );
9 s: d% E' U4 m5 @ }3 G$ I4 j, ~. b1 @; h) t" F6 o
}" o% h8 L' U0 ?, R( m
app.addMenuItem( ...{
) C0 O' C( _# c6 A" v7 v# ?9 l; ?: tcName: "-", // menu divider/ f4 X9 a* T! Z; Z
cParent: "View", // append to the View menu, t: E7 m A( Z7 |
cExec: "void(0);" } );' S& T' M& D; U1 ]
app.addMenuItem( ...{
8 V$ C& Z4 }( n# W7 F) wcName: "设置本页为书签(&B)",
4 J' Y* Q: X% J8 qcParent: "View",( O3 ?" w e1 _
cExec: "AddBookmark();",# m* m/ c. `( D2 {; t! E% L
cEnable: "event.rc= (event.target != null);" } );
8 f$ M( |( N% x$ |+ E7 v9 Bapp.addMenuItem( ...{
! j# y5 d$ Y+ k6 y! m5 ~$ s# ucName: "转到指定书签(&T)",
# E0 x- I0 N n. T# i/ g; X4 ]cParent: "View",
& p7 d, w/ _7 A: XcExec: "ShowBookmarks();",
. X+ }0 Z+ F7 ^2 AcEnable: "event.rc= (event.target != null);" } );
7 A8 m+ z& j) U9 u& t# h, q//cEnable: "event.rc= true;" } );; x2 f* w h$ I, g+ C3 R
app.addMenuItem( ...{
$ d d3 A( l' M lcName: "删除一个书签(&D)",0 b3 U- c8 L3 t
cParent: "View",
- d) X. Y5 W3 ?+ w- ucExec: "DropBookmark();",% L b: O3 A7 i8 d
cEnable: "event.rc= (event.target != null);" } );
" _' n/ b" m3 \( b6 ?; _app.addMenuItem( ...{3 m I# S% ^; x! W
cName: "清除所有书签(&C)"," g. W& Z, Q+ ^6 y
cParent: "View",
8 P/ ~" }4 t+ r& J, B0 KcExec: "ClearBookmarks();",8 N' z3 k. G# G9 P( A4 `
cEnable: "event.rc= true;" } );$ ~, m' Y4 P/ X, u6 y$ |8 P9 k4 E
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下! a _2 \# @9 s! N
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了# Y+ |$ A. _( r4 U- |# P
% H4 U) r( I" H" J7 X/ d
4 d s5 ~3 N; [+ x2 O& w本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|