TA的每日心情 | 擦汗 6 天前 |
---|
签到天数: 2402 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法% ?% w+ m: ?6 Q X ^/ O
1、打开编辑的首选项项8 n' V( ] F( U9 c' r; G& X
" j- [1 c" X N: ]8 R# y2、确保下面的选项都被选中
, t9 P! Z# |3 a$ ]3 @" {5 x
8 B3 X8 Y' @" E3 ~$ Y' D. U- c. E3 把下面的代码保存为一个bookmark_page.js文件
2 K% X- [& ?& t3 d$ }' {// bookmark_page.js, ver. 1.0& {3 d; a- F9 ?8 A* c4 K
// visit: www.pdfhacks.com/bookmark_page/8 U( v5 u+ R' G4 f1 z. i
// edit:cjs 2008-02-17 $ R7 o2 }5 m: ~: L2 H
// 1 修改为中文标签
8 Q! D- o; h9 i5 c- O4 s2 r8 s// 2 设置书签时可以自动获取当前的书名; m, s3 w% P' {7 \7 q
// 3 自动获取当前所在的页码与总页数,方便查阅4 _5 k" O7 m5 l4 S+ k
// 4 实现更多功能可以参看Adobe Reader的SDK
2 F4 `: y6 B# \8 ^" I6 ]- t& _1 @* o& g5 x
// use this delimiter for serializing our array) p& H* O7 `$ T2 J. s% ^
var bp_delim= '%#%#';- c: s4 \# \& Q7 s
function SaveData( data ) ...{; T2 ~/ r3 W1 l/ `0 y% l
// data is an array of arrays that needs
: R( l1 E( R3 B# a+ R" g# g // to be serialized and stored into a persistent
- x4 T/ n5 z$ B- Z E, N3 f/ {( r5 E // global string
: X* A" g" n& J6 P5 L var ds= '';
8 G! T6 s9 G, f z for( ii= 0; ii< data.length; ++ii ) ...{
# ?& S$ n1 w3 l5 S( @, M for( jj= 0; jj< 3; ++jj ) ...{
! _; M7 X# k1 v9 b- f3 e if( ii!= 0 || jj!= 0 )2 |+ n; T) \$ {8 s
ds+= bp_delim;
) u+ e" U! Y. | ds+= data[ii][jj];
. T: p! d' d: O' a; X3 L! B) k6 C; F }, J5 w5 o0 ^ P( i$ I: A
}
1 E/ l% u, i d& m9 V- |7 X global.pdf_hacks_js_bookmarks= ds;/ r9 R) @; r; i; e6 G! V
global.setPersistent( "pdf_hacks_js_bookmarks", true );% C% `, X( U9 c; {5 p6 D
}
Z q+ P# E0 _$ R1 i* m( Gfunction GetData() ...{
4 u! l: ^4 R& w) Z. V1 V // reverse of SaveData; return an array of arrays
4 V- x3 {# Y! T1 N+ j: O. X if( global.pdf_hacks_js_bookmarks== null ) ...{
0 I* j1 r0 e5 R% A8 s* K5 @* s return new Array(0);+ u4 T6 `& e$ ]/ {
}
) P" Q: w) o* h* Q var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );. P) Y, K! Q9 n g4 r3 z
var data= new Array();
; e7 _; {5 y" H for( ii= 0; ii< flat.length; ) ...{" z) s' d; \5 n2 R% Z# s
var record= new Array();
. b) D) f# u( {2 a: n+ @ for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{+ ]2 q2 e2 M/ z% p; E, f4 x
record.push( flat[ii] );) ^* R$ }; }2 p3 Z2 d/ u
}1 u |& a- F; y: d' h( q" N. H6 I
if( record.length== 3 ) ...{: T' m+ D( X/ Y2 N, I+ K
data.push( record );
7 q; v+ Q6 C$ P% t+ ~ }$ n+ f+ p/ P0 e2 a
}1 s: h/ N" E& x* v3 g0 ?2 w
return data;
- ~& \1 J' M% x# f, D}2 m6 l- f* f: V3 ?/ P: X
//Get Current Date
2 y- \: u& Z) K5 S4 afunction DateNow()...{3 s/ q# \* b, o
var d, s ;) U/ _$ h0 {* K. {4 S4 {8 D
d = new Date();
# e. u" {: L' D% U" ]0 x- E s = d.getFullYear()+"/";
+ J% P5 N& `1 a( Q1 T s += (d.getMonth() + 1) + "/";3 \! D j! x% f4 Y( _4 e5 J3 z9 V
s += d.getDate() ;; ?$ A0 j5 `$ W% K* s6 u
/**//*
0 I1 A5 s# w$ x% @ s += d.getHours() + ":";) T8 S$ i3 Q7 n9 ^/ v
s += d.getMinutes() + ":";0 e; y) I. b0 Q
s += d.getSeconds() ; x/ A$ a8 P L$ u: r
*/, S" x/ m/ n& {: }. @
return(s);! d- c; ]/ ~$ B" p, j+ }4 P- L6 L- W
}
, w, e2 ^* o. B) C+ R; q; n! Y' h$ H& q
function AddBookmark() ...{
5 L3 F; o& u6 J$ I" p6 X% j // query the user for a name, and then combine it with
z, ? V( W. n$ }& c; { // the current PDF page to create a record; store this record) z7 L" S+ z8 h' [/ ^/ e
var thisfilename=this.documentFileName;2 f7 h9 M& y# M1 r% X0 {3 i0 ?* s
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));7 @; V0 f: t5 ~* J' T( E
var numPlugInss=this.pageNum+1;
5 B, X, S- F* h5 @5 e/ v var currentdate=DateNow();9 D% H' i2 L1 K& Y: o
var label=
6 `7 [) C# o6 {2 M& V6 Y app.response( "书签名称,可以修改以便于记忆:",. H0 s4 }7 y- o3 q _3 f
"书签名称",7 Y: I" K) A8 h6 ~" K8 E
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,6 S2 h# K) K6 e4 ~
false );
: z! `( N! Z" y! k3 G ] if( label!= null ) ...{
1 r, P% r% A5 t) t' h' k# i var record= new Array(3);0 D( [4 F4 V5 ~1 E
record[0]= label;
# M# S7 K, x! ~' i- y7 m! w. K0 a9 ? record[1]= this.path;& S$ e, ^ N! `. q" a6 x% I3 k) j
record[2]= this.pageNum;6 h$ \/ v: m3 Q# g; t9 z' h
data= GetData();
4 }, J3 [; M% Q Y! z data.push( record );! k( n" }: O5 C+ S# m; k& _7 Q
SaveData( data );
- u& [: c M# Q, x$ N1 o }
1 t, L* V6 L& E3 o# Z}- n; q( L& l2 {+ D/ I
function ShowBookmarks() ...{
" `% g( y" M+ h& p2 |# F8 } // show a pop-up menu; this seems to only work when
* Y2 L5 y" J3 G8 o& f: F // a PDF is alreay in the viewer;
) y6 X [1 [% P7 D var data= GetData();
: F3 j0 ^6 J* @4 s: r var items= '';
, j+ a- K& A3 R5 Q4 o for( ii= 0; ii< data.length; ++ii ) ...{# U' s# F( m' a5 T0 Y) J7 d
if( ii!= 0 )
- S' G6 K5 _; n6 A& I! } items+= ', ';5 m/ p/ O6 G3 n2 @* `! \' y
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
3 _: Y/ X; x |; T9 R- s9 p3 a }7 r! m) b% K( ^# B
// assemble the command and the execute it with eval()
" b/ T$ y- o" x, m4 F; n6 ~ var command= 'app.popUpMenu( '+ items+ ' );';
3 j! I( S: o* k6 r" ]6 P6 a var selection= eval( command );
5 O+ C4 u4 x4 S6 ?% Z if( selection== null ) ...{- O( c `) z! J) K6 }7 _. m# ]
return; // exit
$ I6 J+ d" Q$ F2 ]+ g } l/ w7 }2 r4 x {7 `
// the user made a selection; parse out its index and use it
# \* Y7 R/ G8 O+ q& B! E' g6 n2 _. L# u // to access the bookmark record* h6 n/ U3 H1 P6 u0 J, s% x6 W0 ?5 C
var index= 0;" I) {# c. ]8 k9 F$ r" U) e) A+ l; R9 f
// toString() converts the String object to a string literal; _7 E( y1 e r6 q- m! [: Q
// eval() converts the string literal to a number
' [& d1 q$ i& ^+ B& f index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );) t+ k K; N2 J f V, t6 R/ V
if( index< data.length ) ...{6 z$ P5 s* K& {' o
try ...{
4 ]* F+ m9 c8 e, B9 G4 A2 A // the document must be 'disclosed' for us to have any access4 Q2 X# ?6 |9 F8 _' L, Z) h
// to its properties, so we use these FirstPage NextPage calls' l" Z+ ~: d5 `
//
) Y2 B2 G) S1 m8 p2 H. P k# k app.openDoc( data[index][1] );
6 s: |4 x/ n0 E( _( ^* r- F app.execMenuItem( "FirstPage" );
' v h0 K( c: \! Y& A, A# u for( ii= 0; ii< data[index][2]; ++ii ) ...{6 x% v# M6 d' {2 i: k/ L$ a
app.execMenuItem( "NextPage" );1 E% [8 ]$ X P! e9 i8 E/ ?# @
}- y6 V$ V9 x/ @& l
}/ ~1 [: l# E+ @: S
catch( ee ) ...{
) W& h3 ]* B/ _% {3 w3 P# S0 T var response= . }3 w2 \4 f. o- t: t7 f
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");! \8 O$ G0 \) `4 x
if( response== 4 && index< data.length ) ...{7 x" G, m) E1 [: K' y+ d) G) f
data.splice( index, 1 );
# R. w. l9 N: c" Z+ b e) H SaveData( data );$ F( G/ A2 J# C& V0 F/ ` ~
}" F2 @) c$ n2 A: l
}1 g. ]9 [* M1 `1 {
}) a, _6 @4 `8 q: y$ G) f, H7 Z2 e
}: H) n) J' a8 T) m. [( j
function DropBookmark() ...{
& u0 T; _6 G( [4 H6 s' H" w // modelled after ShowBookmarks()
. Y/ \* D4 I M( L var data= GetData();
F' u9 O' j- J# q# g- w+ A; w var items= '';
/ J# \2 V% R! G T' C. r) l for( ii= 0; ii< data.length; ++ii ) ...{4 M3 d) K) h3 r; m* \' c6 X
if( ii!= 0 )
+ O% s2 w8 J$ X& F/ N items+= ', ';
! `; t3 T) g7 e+ D4 h items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
' J) q# q( V' D5 l# Y6 | }
2 M$ v h0 Z# t- Q var command= 'app.popUpMenu( '+ items+ ' );';
- m. K. M9 v9 ~4 O5 n4 g1 Z var selection= eval( command );. y" f& \$ i: ]
if( selection== null ) ...{, X" a" H9 T" l& J1 m; x% \
return; // exit
$ F3 D( Q2 v% x }
) c- e& m f9 u: W4 f var index= 0;
: v. Q2 L7 _1 w ~% C index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
$ B) K1 o ]9 |6 J) u" n" F if( index< data.length ) ...{" n) A% h4 N& S/ [0 ^
data.splice( index, 1 );
6 \+ g' t5 u9 ^ p; i; f6 G& \: U# x SaveData( data );
& i7 U( i, s4 a. e6 e8 y }6 s2 b6 S0 A8 F
}
# I! G0 @6 M7 d$ w9 ^: W" xfunction ClearBookmarks() ...{+ F" \ k, ^" M, q2 B
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
R) k: h. y8 x# m1 z SaveData( new Array(0) );
' E, q6 D+ T# g' V" w* F }
1 u8 b6 o! z+ s+ ^+ n}
3 O& ?; p1 }) R4 Mapp.addMenuItem( ...{, w! h( b# w3 x) |
cName: "-", // menu divider
6 A( d+ W5 ~9 t' C% @- scParent: "View", // append to the View menu
: f1 t) O. E. C4 ycExec: "void(0);" } );0 b6 R: |$ N6 r" E/ |
app.addMenuItem( ...{
8 q( F6 x% W) t! ?3 NcName: "设置本页为书签(&B)",5 |' ~" ]5 a& {9 e
cParent: "View",9 k% W* m' n9 @( D# m1 i
cExec: "AddBookmark();",
$ Y# M- y* ]/ Z6 F1 v2 BcEnable: "event.rc= (event.target != null);" } );
i! P4 b9 b7 f! n4 japp.addMenuItem( ...{4 @3 v; I6 i/ K# l
cName: "转到指定书签(&T)",
6 T; f C9 v2 ~) ?8 y: k- jcParent: "View",
( _& G* w9 P' O, ocExec: "ShowBookmarks();",
' j" }5 z6 w$ v- J, EcEnable: "event.rc= (event.target != null);" } );3 K+ I. b! u3 T1 q# n) L& z& x
//cEnable: "event.rc= true;" } );
e9 I% f5 ?( Gapp.addMenuItem( ...{
, }) g% ]3 j; Z9 i" ocName: "删除一个书签(&D)",5 J1 N% o& i }( ]0 }" g( V
cParent: "View",$ f- b$ s' P, C* s* f
cExec: "DropBookmark();",9 W9 L" [) r0 v3 T0 M4 M& Y
cEnable: "event.rc= (event.target != null);" } );
) ?( C5 c0 J3 p+ ^+ napp.addMenuItem( ...{
8 q$ E% K7 X5 J, _2 T+ O, rcName: "清除所有书签(&C)",
6 ?$ b! _9 ~3 B: @# ]cParent: "View",
; i5 @ M9 G0 s8 EcExec: "ClearBookmarks();",
0 K4 h& g+ p9 Z! w; \' BcEnable: "event.rc= true;" } );
! m, i' P9 Y! y+ o& g G, N+ J4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
- j3 P0 a, r F+ c* e5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了) H C+ G/ e; u1 _ y+ d- m% m
, Y4 w) c n$ Q' y" M
8 m$ K4 o( J+ B$ o% ]本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|