TA的每日心情 | 奋斗 3 天前 |
---|
签到天数: 2370 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
- k# \( @& @4 W9 s; C% v, k1、打开编辑的首选项项+ i, J: H, i, m2 c
* e L$ x5 L2 `6 q5 `; g2、确保下面的选项都被选中4 R- ^# G2 h4 z$ q7 ?" y0 D5 t
6 d2 s# n! v: e0 a6 U
3 把下面的代码保存为一个bookmark_page.js文件+ k5 G8 ~$ |) Q% @, E+ I4 J
// bookmark_page.js, ver. 1.0" V a" _9 Q$ R* X6 H& [
// visit: www.pdfhacks.com/bookmark_page/" ^ @. k9 s* K1 }* p
// edit:cjs 2008-02-17
8 f; }6 o% Y2 g// 1 修改为中文标签' W0 ~! X- T' L. x) ?
// 2 设置书签时可以自动获取当前的书名, G R# `! ^8 T3 j4 U
// 3 自动获取当前所在的页码与总页数,方便查阅- }7 u- k: k9 n$ E8 z
// 4 实现更多功能可以参看Adobe Reader的SDK
8 q1 @9 Q1 m. @- a# [8 S, |% p2 }, [% K# q2 k% r
// use this delimiter for serializing our array: m, j* P+ d- D8 g- u
var bp_delim= '%#%#';- K6 M/ U0 U! `5 P Q. |
function SaveData( data ) ...{: F m' u0 a7 k) j' u( Y9 I" y# h
// data is an array of arrays that needs
4 [4 ]4 W5 B' V3 D# [$ p: p2 o // to be serialized and stored into a persistent
/ `9 v3 g! d3 u' ~( ]. U // global string
, h) x& w4 q* [' P4 d- K, l, N/ t var ds= '';1 c" p8 q' ^5 J# n
for( ii= 0; ii< data.length; ++ii ) ...{1 L2 V# _/ p! ~- x( H
for( jj= 0; jj< 3; ++jj ) ...{2 [' }5 |6 K: m, W3 R
if( ii!= 0 || jj!= 0 )
9 B) W1 M; @3 d! ` ds+= bp_delim;+ P4 j) A: R, h8 V$ Z
ds+= data[ii][jj];" K. ?4 \; l# P7 I5 H: t/ D
}
8 N1 o+ e! k0 r7 M. o% ]: c' ^ }/ A) _8 i% J! T( \- K/ n
global.pdf_hacks_js_bookmarks= ds;
! P6 H& _. k/ t& h% U8 S. T1 h global.setPersistent( "pdf_hacks_js_bookmarks", true );0 {; c8 R. n( X
}: s* f5 A A: A. G5 w
function GetData() ...{# I) }) m% J3 o. h
// reverse of SaveData; return an array of arrays
4 {! i; h% s5 B3 p/ z if( global.pdf_hacks_js_bookmarks== null ) ...{& a$ G0 t' w2 `$ G0 B( k3 y
return new Array(0);5 |8 j3 q, [, V- |" w0 J5 h
}
/ Z) J4 P3 ^2 x# [9 ?- B var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );2 q+ C5 x' g$ W: G! l- i' }6 Y
var data= new Array();
9 b' E) E/ `) H( `7 G% m for( ii= 0; ii< flat.length; ) ...{) b2 C, J5 U$ M) `
var record= new Array();
: N% \. N4 u4 N9 G for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
9 L4 j6 ?- o" ]2 v( l \7 u record.push( flat[ii] );
7 l5 h: ]9 z3 d. V* [6 J+ a }5 Z' y& N" D* u/ \ M6 e& L9 ]
if( record.length== 3 ) ...{
$ u9 R2 `: J8 e* H% W( [6 Y1 F5 s data.push( record );
/ K/ |. d6 C. F$ l. F# h5 J }- U+ }' }$ h; W: k5 j; }, |4 B& M
}
8 G3 Q6 B5 T9 v+ k4 I return data;
; g G! G7 }2 R6 H5 X& {9 S5 B3 j7 m}
' V4 n A# J" ^//Get Current Date
4 |( }. Y2 \3 W0 Wfunction DateNow()...{6 U+ F& z+ ?* _4 ~
var d, s ;9 B0 Q/ \' F$ v% ^$ C) c) ^+ \( h
d = new Date();
4 q- M. B9 U' S4 c$ e9 P$ ` s = d.getFullYear()+"/";
; W. ^: I% _' r* z+ L; Z: E s += (d.getMonth() + 1) + "/";
" b1 s4 A% s: A* p" h; N s += d.getDate() ;
2 b" t0 \* f' A* O z /**//*3 x6 R. K6 m4 k: }
s += d.getHours() + ":";
8 h3 L" c: P1 { s += d.getMinutes() + ":";* W1 R! o X+ e3 N; q% ]
s += d.getSeconds() ;" ^& J9 v( E1 e! i5 J4 `
*/
0 m! _0 ^0 T. C) f2 t; I return(s);$ {% }6 d5 S5 ~6 S
}& P- o1 w% Q \$ h5 w' s
% m2 Q$ d/ x/ zfunction AddBookmark() ...{( W; x! w- F- I: o' R" }) R7 i
// query the user for a name, and then combine it with- V9 x3 M8 z% K% _4 k4 \- \
// the current PDF page to create a record; store this record, y& k3 v$ k+ e/ c. s2 W
var thisfilename=this.documentFileName;5 \0 I9 Q' K+ z# m% X/ Q2 k3 I4 q, B
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
/ ]6 V9 Z4 Z) u4 n1 j var numPlugInss=this.pageNum+1;
/ H7 J, \' W9 j& [! f' s( D var currentdate=DateNow();' L; W7 t4 I; x$ h/ {+ p0 U
var label= $ n/ t: @! m( p! T* p d
app.response( "书签名称,可以修改以便于记忆:",/ k& e2 Q$ t7 u! u7 S
"书签名称",
- X( e' O1 ~. k8 S) a! ~ "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
# Y* |: H& O& v; Z/ n7 N false );+ j( g* @; Q! L7 i
if( label!= null ) ...{1 _) z& ^$ x1 ?1 k7 A
var record= new Array(3);
# T% ?$ C! q! T0 U8 B* v" g% d record[0]= label;
- d6 {7 b6 m% ?2 B# ^6 U6 X' E9 G, H record[1]= this.path;; _ O$ b1 f3 Y
record[2]= this.pageNum;
' z8 t! C; x3 j3 F. w/ W5 e8 W1 } data= GetData();0 s l. @/ q$ P$ Y5 T
data.push( record );
% E9 o: Q5 u: E- { SaveData( data );% w: o* ^4 o% K( U4 U$ E
}
: r% r+ ]6 f6 }; S+ t- x# g}
, [$ C( Q$ K' Z; Sfunction ShowBookmarks() ...{8 t* N. `6 s+ Q
// show a pop-up menu; this seems to only work when# l5 E. w& } I Z+ t! q4 D1 ~
// a PDF is alreay in the viewer;9 C# _ `% x- c) t, W
var data= GetData();5 `8 A# J8 N/ ~+ k0 E
var items= '';
+ X' O! @0 f% | for( ii= 0; ii< data.length; ++ii ) ...{; Q' ]8 ~5 _/ q' b# y3 T& \
if( ii!= 0 )3 y6 |. J" p9 X7 I$ S1 c9 S3 n
items+= ', ';+ U2 b( v8 y# z+ z2 s5 o" ^
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
; a3 P0 _$ ]! q. r Y) K }
T/ g3 G% L. x5 p9 a5 K3 b$ j8 Q // assemble the command and the execute it with eval()2 n' H, p# o4 u
var command= 'app.popUpMenu( '+ items+ ' );';
# P8 d2 M# p. g& Z6 N var selection= eval( command );! B! A/ i+ x! b% h3 O, B+ H
if( selection== null ) ...{
. \# T$ I5 B; J H return; // exit
2 M. H/ ~3 I* n+ m7 u }6 B$ H) }9 g0 q- C
// the user made a selection; parse out its index and use it3 p2 C- y- r5 V; \, m$ L
// to access the bookmark record
# _: `. X- Q% L! Q7 J8 z) @& l0 a2 a var index= 0;, w2 X( G7 x2 V6 X, @- H
// toString() converts the String object to a string literal2 W9 K6 T1 I" q* h
// eval() converts the string literal to a number
2 P& R. p6 H5 {/ l5 u) p# H, x index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );( ]: }, W {+ O! m9 @
if( index< data.length ) ...{
" F0 W, e% e/ k6 k3 k8 ^9 L. z9 @ try ...{5 E% o& i( j5 Z7 v
// the document must be 'disclosed' for us to have any access5 O4 q! Z R- G& |3 ]: c
// to its properties, so we use these FirstPage NextPage calls& U. F! C% o" d- H# ~
//
# K, n z9 p2 i; ^ app.openDoc( data[index][1] );
# [/ n7 N1 `- c4 J; n; K% Q2 b app.execMenuItem( "FirstPage" );
# g& k8 x; P9 Y for( ii= 0; ii< data[index][2]; ++ii ) ...{
# F. d; K4 U6 y/ J6 B5 x8 n y app.execMenuItem( "NextPage" );
& _, p$ H! P) M }3 U6 _+ W& ^0 g& C" H5 P
}
9 E# K9 f( E2 ] catch( ee ) ...{0 ]/ H( ?5 q) N% ~0 O, U
var response=
; q q2 W8 T" B( v' x, [; d: Q app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签"); z* ~% [& T2 V9 P' h( B3 `7 K
if( response== 4 && index< data.length ) ...{
" |2 `% v4 z, C: O2 ~( D, j data.splice( index, 1 );: B" K2 T6 E. g) ?
SaveData( data );
@# x. Q' n( G& A }/ X; t+ p2 V+ L# g; E
}- M/ H8 @4 `2 Z8 f
}& X: D5 e4 w3 d! L g2 g
}
8 u4 ] a2 b# @4 Ufunction DropBookmark() ...{
; {* ?( k, U' j0 Q // modelled after ShowBookmarks()
$ y- e$ H7 X) \% }/ S- M var data= GetData();
' w- }& l2 z! z c& J9 e, G( \- K var items= '';
, @% Y2 Q3 x h5 r0 ^ for( ii= 0; ii< data.length; ++ii ) ...{
4 Z1 e0 O o$ g" ` if( ii!= 0 )
& a: E2 Y' r& n! w, }2 p items+= ', ';2 h0 A# J$ `. X% C* H$ O" n
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';3 V; C/ S, a1 U8 d+ t" u" J
}( C- S8 g8 T$ u* I' q& X
var command= 'app.popUpMenu( '+ items+ ' );';' Q( F& K: V& q7 F2 J% I
var selection= eval( command );
, N* W! H1 y. a4 d4 l2 \ if( selection== null ) ...{- t: B6 S- ]+ _2 ^1 X& s3 {' |' u
return; // exit
# {- J; J% E% [: W7 F }' C* ^+ z% g# I3 X& k9 j |$ ^
var index= 0;- N0 K# n: j6 o& z0 _/ O3 B: }* w
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );. e+ C' G! S+ }9 x& `
if( index< data.length ) ...{5 R; |( p3 u, g, x0 p; V
data.splice( index, 1 );* T1 F$ \7 q- j/ x+ m1 v: J7 K
SaveData( data );$ L/ J9 ?6 V1 U4 C c/ ?+ e
}
5 M' g6 f5 T/ g* p}
4 _* Z' \1 Z5 V" A6 w1 ofunction ClearBookmarks() ...{
5 N; ?5 ?) @" y( e if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{& I2 g5 N9 Y/ e- H! F3 E
SaveData( new Array(0) ); }4 V$ y2 u: y8 P; Z! { g
}9 j* l# ^6 ^7 H
}
! n% O% ~ [( `6 x5 Uapp.addMenuItem( ...{
3 }" {) E5 N; ^* Y4 ]" kcName: "-", // menu divider% q- _: L: u# l( j; {. ^- h) I* c
cParent: "View", // append to the View menu
: d) _1 L; J) u; n- PcExec: "void(0);" } );3 Z: t N# a5 ]% ?; Z' i
app.addMenuItem( ...{- B* e0 O/ m1 D' g1 c- R& D/ a
cName: "设置本页为书签(&B)",& j# M/ S2 C0 q+ ]5 v$ C
cParent: "View",: Y3 Z! Z( r' S2 V* ? {# }6 t6 k
cExec: "AddBookmark();",; ]/ q& m6 v0 k7 w$ Y6 Q
cEnable: "event.rc= (event.target != null);" } );
1 P: k9 B2 Y* v5 k) W, d5 vapp.addMenuItem( ...{, K7 ]" ]; H0 c6 E, k) q
cName: "转到指定书签(&T)",* o, U* v$ T8 d& L; \7 L0 J
cParent: "View",* o& q. T& ]) r& I; Y0 X
cExec: "ShowBookmarks();",
" U0 A g2 {1 O; Q+ z: ~cEnable: "event.rc= (event.target != null);" } );
; S7 }! k3 i R, O+ e1 g0 ]//cEnable: "event.rc= true;" } );& i3 j$ i3 }* _7 ]
app.addMenuItem( ...{
; w# z! K8 o5 n1 f5 c2 e+ |) X' XcName: "删除一个书签(&D)",
; ~- y. X8 i# n3 fcParent: "View",
a9 H/ J# f+ @ J* |9 zcExec: "DropBookmark();",
# N1 y1 w i2 I! ycEnable: "event.rc= (event.target != null);" } );
% E: |# T9 _& c5 {app.addMenuItem( ...{
: t6 ]! y( L' E8 O$ H" V6 ]. T9 zcName: "清除所有书签(&C)",
& S% U' \+ @ O1 |cParent: "View",
6 @2 \+ E- O2 f7 q/ `' Y6 RcExec: "ClearBookmarks();",
' P1 Q8 P" M9 e' Z3 KcEnable: "event.rc= true;" } );6 L7 S. }% N/ _. i: [- P5 b% [+ A
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
, }& u; a9 {( y1 M( H5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了4 _! f% [: C! c8 L
6 m4 w# X% k2 H; Q; L ^5 ^1 [
/ m* C! D/ `; A& w- U5 d2 [本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|