TA的每日心情 | 奋斗 昨天 10:28 |
---|
签到天数: 2370 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法6 ?. q8 X+ j* s8 V2 e7 d: ^4 A
1、打开编辑的首选项项
$ m! t5 O T4 N0 n
* P: n: n! |3 ~9 Q$ B( X2、确保下面的选项都被选中
* |( Y( ~5 v# d# v" F5 _" X
" c: T. w* M* a3 把下面的代码保存为一个bookmark_page.js文件( t I3 \) Q2 P6 q
// bookmark_page.js, ver. 1.0
" m9 V( H4 ?+ h. D) S7 z$ W// visit: www.pdfhacks.com/bookmark_page/' e/ e5 z9 u! T- Q, z5 N( b
// edit:cjs 2008-02-17 ; L% q% [: _$ I% F' m) t
// 1 修改为中文标签
2 J' @9 I) @$ S* i// 2 设置书签时可以自动获取当前的书名
+ `4 X- D& d$ W// 3 自动获取当前所在的页码与总页数,方便查阅% N' B& u: o6 m) i# d( o
// 4 实现更多功能可以参看Adobe Reader的SDK! X" w7 T" U+ e7 Y
3 z0 l1 W9 v4 V& e// use this delimiter for serializing our array
$ H9 }7 B2 C0 L( t0 o7 Uvar bp_delim= '%#%#';' [9 \6 l# H5 A" _ K
function SaveData( data ) ...{- y% [7 a/ o6 x0 ~4 o1 h# g
// data is an array of arrays that needs& Z2 S+ K( g* w0 Y2 _
// to be serialized and stored into a persistent
! t8 o+ Z% }) t. U- k // global string
[2 u' ]0 @5 M7 g0 n0 e" v var ds= '';
! @/ q: h8 ~7 ` for( ii= 0; ii< data.length; ++ii ) ...{
5 W) v9 k4 H9 ~' B' z for( jj= 0; jj< 3; ++jj ) ...{
0 B) t) c8 p+ q! p if( ii!= 0 || jj!= 0 ): H3 v/ e- ^) l/ w F& f
ds+= bp_delim; Q* b- X6 P( Z0 P. ~# A7 @$ Z
ds+= data[ii][jj];
& K3 A/ o [7 V }% r4 r, i1 o) E' g; f& `3 Q* R0 k
}6 g! w! g: ~9 }7 ~1 }; d" N3 [0 y
global.pdf_hacks_js_bookmarks= ds;
- K( O! d, u0 K8 F2 L o global.setPersistent( "pdf_hacks_js_bookmarks", true );
$ e9 K# D# Q7 d& k}
% C9 D) x# M' q+ ?7 tfunction GetData() ...{! }! p1 l. ?. y% M6 a
// reverse of SaveData; return an array of arrays
! }0 g* D. M8 j if( global.pdf_hacks_js_bookmarks== null ) ...{. X: ~ s# U$ U+ l7 a+ m3 c/ }6 G
return new Array(0);4 t" n; U" r/ |' [! h/ M& q# k0 P
}( z0 z! g* ]+ v" F% L
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );4 _ v2 |" z; c
var data= new Array();; R+ F$ I. \7 L, i1 H5 j' ]
for( ii= 0; ii< flat.length; ) ...{
6 `6 U4 m3 E6 n, k9 C) c: S var record= new Array();
4 g0 w! s$ T) W9 T D# G. C for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
. ]# g9 `( f1 X4 O5 S% ?2 @* R! T( h record.push( flat[ii] );$ ] \: q, Y' ~# }3 `
}
% T1 f _, G7 G! A" M if( record.length== 3 ) ...{- T0 _" t$ I8 m% y+ ~" r
data.push( record );8 S U% n0 ?+ @1 G
}
/ E p( s2 c1 T% V1 { }& w9 \$ R! F+ W0 `
return data;
1 q( ~0 U4 J' f7 [}4 c8 s) C5 C1 o8 Y
//Get Current Date
" b4 s. H/ J2 E- r* Q2 `1 H0 Pfunction DateNow()...{
2 r$ K% B W: F) d: }# b4 [0 y$ x var d, s ;7 H! A, S9 e7 s* j* o, e
d = new Date();
+ B( O9 g, q4 E1 C5 W s = d.getFullYear()+"/";7 d; S& n! X8 i0 `) }3 e( u
s += (d.getMonth() + 1) + "/";
* F6 }( W% ?+ F- R* z' V0 A* {( B6 ] s += d.getDate() ;
+ M0 U4 Z* [* [& e1 t: D /**//** b6 m, o" k. D; x, d
s += d.getHours() + ":";/ i1 H! l) F, H+ a
s += d.getMinutes() + ":";
" g3 E4 A" K4 O% e0 t D6 b s += d.getSeconds() ;/ \( |3 I) [. E0 m6 |0 \4 Y+ t" b
*/
2 S: `1 ^6 ~6 {8 M9 l return(s);" p o' J- m6 n2 J
}
7 [$ D* k8 Y: M5 \: ]% v3 u& o1 q" v6 Q: [
function AddBookmark() ...{
3 D! o; s8 o0 Q: w0 b // query the user for a name, and then combine it with3 E6 {6 C [5 o% k5 x0 {: y
// the current PDF page to create a record; store this record' ?; ~6 A% Q- K/ u7 I9 ^1 F0 U+ o
var thisfilename=this.documentFileName; d& Q8 s* ^$ A6 s& ^ j
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf(".")); n" z" p; i4 s) Q# s, b: p5 m
var numPlugInss=this.pageNum+1;
0 u0 m$ j- E" [' X! G4 r var currentdate=DateNow();9 E+ S h6 A. J$ K' S0 N+ ]. v
var label=
& E4 l3 u% {( d app.response( "书签名称,可以修改以便于记忆:",6 F; i5 @' |/ Y
"书签名称",
% B/ b. Z0 {" P$ \8 {; R "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
* w5 s% U! z: D false );
6 i; m& d. X# X1 X if( label!= null ) ...{/ y$ ?) W9 |) I6 e
var record= new Array(3);2 ?3 N" y0 @, C) K$ b' l
record[0]= label;
4 @& c' l) q# ~. B9 D record[1]= this.path;2 Z, w, |3 D0 [9 t0 U
record[2]= this.pageNum;+ B& p' W- }( ]) o
data= GetData();* H1 t) w1 U% }& R9 W; S
data.push( record );
$ W% j2 s6 f% N4 l( j2 ]2 H SaveData( data );
4 c$ ?# O4 ~7 k. C; `1 v }
' q5 r' Q# N2 @% N" |}
# D8 Y! r( D$ N. M) l: q0 }5 efunction ShowBookmarks() ...{
4 n6 Y8 t: L6 m6 ]4 D' o // show a pop-up menu; this seems to only work when
5 N3 @) G. T1 [ // a PDF is alreay in the viewer;9 Z3 J. k, c: F" w
var data= GetData();; B+ O% N L2 ^- d" Q/ s' |
var items= '';: }- t E3 _# p( Y, e7 N1 J+ {' p. W6 H
for( ii= 0; ii< data.length; ++ii ) ...{. V/ ?" z3 V1 y2 E* f
if( ii!= 0 )
5 T2 C; |, N! q1 W4 G4 K items+= ', ';
5 R5 Y5 P5 }/ d. r0 { items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
# k+ i2 _$ ~* O2 B B }
) L" {( A/ J& h: k4 {- c+ A+ ?; r // assemble the command and the execute it with eval()# k+ k# f2 W- b$ |9 j T% E3 Q
var command= 'app.popUpMenu( '+ items+ ' );';
3 [ c3 S2 @, C4 {7 w$ c3 ? var selection= eval( command );
9 `# }5 s, s% Q if( selection== null ) ...{
" _- R5 g7 u3 n: {: ]$ {( a return; // exit0 c: O; ^3 Q- K0 E' n
}
& r* @ g; q+ M) A6 G // the user made a selection; parse out its index and use it
* ^; U' Z1 H b( P9 h6 W# q // to access the bookmark record
& a( L' b6 F6 X2 m' J. E2 f: a var index= 0;
$ Q3 ]8 M- n) k' u // toString() converts the String object to a string literal
" z# \' ^+ H; Q9 s l. y+ e // eval() converts the string literal to a number
5 O' K+ H0 G' f" W6 ^ index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
; y. ~& J, r) `$ U& H( R+ C' c8 ] if( index< data.length ) ...{3 o4 S4 Q U l0 Q- u" |
try ...{
- Y& A/ X) z' `% w! n // the document must be 'disclosed' for us to have any access
$ c, B) d2 P5 _ // to its properties, so we use these FirstPage NextPage calls
' D% `- R, C* v9 c" @. l //1 F5 h0 \0 |2 J2 s1 g9 h- C+ a
app.openDoc( data[index][1] );
4 X& P: K- T; v6 u( Y8 l0 f. T app.execMenuItem( "FirstPage" );, q' q+ Y6 j9 l& ?
for( ii= 0; ii< data[index][2]; ++ii ) ...{
9 [3 v. C$ e. ^$ D, R. h K app.execMenuItem( "NextPage" );
; o, x7 G0 x$ q7 r! O" I }
! i0 a9 I- n7 d6 ? }$ @+ R: e7 Y5 C. r/ P4 l2 @1 F
catch( ee ) ...{
7 P+ i: X/ c! o, N$ E& N var response=
$ }$ F! t4 @( R: \& m1 I. A/ Q app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");# w, v8 I o9 {/ o2 n B `+ Y" d. F% P
if( response== 4 && index< data.length ) ...{% W* k. {9 ?# r0 t7 g' Q6 @$ S
data.splice( index, 1 );
( u k2 \. p& z! S$ N SaveData( data );
/ u" x- Q% H7 h }
$ s* O$ m* {1 m0 S& H3 s }& W; f5 A7 g( K9 t6 I" c
}2 v) R9 W) R6 K
}' n+ o% |, F; V$ P8 F: B0 s
function DropBookmark() ...{2 f) i- |7 m( c2 {/ P# w+ ^5 ~, D$ |
// modelled after ShowBookmarks()
3 a1 k. x( F5 [4 ~8 @ var data= GetData();7 R8 I7 w$ c) p8 F' |4 d% T4 H* `( N
var items= '';
& I X: d* c$ {$ q" R! c. j for( ii= 0; ii< data.length; ++ii ) ...{
* V6 d, W$ ]5 _, r if( ii!= 0 )0 @- ]3 {5 ]8 p% S+ o
items+= ', ';$ f/ U8 k# Y( i* K0 _- y
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';, d; y$ d$ s5 |
}
; D5 d" \: Q% l var command= 'app.popUpMenu( '+ items+ ' );';
- k. e, l8 P4 G+ W3 }, a var selection= eval( command );; b5 T* {2 Y2 q8 n' B3 k, X+ q
if( selection== null ) ...{' S' C% ^. ?2 v% ~& w
return; // exit# K1 d+ G4 U7 Z3 \. O
}
' i+ l# ?& G* t$ C1 o var index= 0;
; o: L, s; m( E% i; u$ H t index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );8 H: c9 l) L# ~ c$ ?; u/ i0 g
if( index< data.length ) ...{* `% \* K( F( n. c/ _
data.splice( index, 1 );9 p! b5 G9 j+ D/ k6 }8 Y
SaveData( data );; F* `: O3 R2 n/ g5 J- @$ o5 c: b- m
}
& M- s" |' ]) C: {( W}
+ j' w7 X9 d- B7 V& Cfunction ClearBookmarks() ...{& f- C% c* ~) c7 ^) t# u8 u+ D8 M# K
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
8 S! f0 F$ B" u1 m' l SaveData( new Array(0) );
) ~7 x& t' Y) M; n }$ a/ N+ x! e* c9 B
}
: d' {! v. _2 t5 M6 s) I Rapp.addMenuItem( ...{
% E) \. I6 X; Y8 X' `) r7 h- ]4 IcName: "-", // menu divider# F' ]) A8 i' N' ^
cParent: "View", // append to the View menu8 N9 J* A6 d2 b, B8 W
cExec: "void(0);" } );
5 `1 B" H3 J) s+ ^$ f- Zapp.addMenuItem( ...{
7 l; w8 q2 z' ^cName: "设置本页为书签(&B)",
0 _/ F5 ]# o# s+ V+ B( PcParent: "View",! c+ \5 u. @1 r) v" \
cExec: "AddBookmark();",: w2 `9 x& C' I0 @; Z: H
cEnable: "event.rc= (event.target != null);" } );$ d, e2 t* Z7 p2 n2 Y8 I; `
app.addMenuItem( ...{
; N, G" } i5 L/ H5 g9 EcName: "转到指定书签(&T)",0 |( f0 l2 w; W E* P9 {
cParent: "View",; W5 S4 N+ m- H/ X
cExec: "ShowBookmarks();",( O, n7 X) O6 ?7 ], Y2 M% ~
cEnable: "event.rc= (event.target != null);" } );
! q, a9 `: w( T) K# e; B; B$ |. X, ^//cEnable: "event.rc= true;" } );
# T$ e3 x3 b! N! u" E7 }app.addMenuItem( ...{
7 i" |: M, ^. p) k, L# }$ h" {+ bcName: "删除一个书签(&D)",5 N2 j1 @+ S9 w1 H, Y9 y n4 z
cParent: "View",
5 d. }3 r7 ]3 `; X, P! m% i1 { }; N+ q2 LcExec: "DropBookmark();",
6 S% Q# ?1 R$ P, DcEnable: "event.rc= (event.target != null);" } );" T. _6 ^. x' `( S
app.addMenuItem( ...{
4 W; \% T# ` J1 u& U7 dcName: "清除所有书签(&C)", Z6 Z N0 w' a7 z- \" f
cParent: "View",
6 F, P) \( r4 u1 u. J% v4 g8 LcExec: "ClearBookmarks();",
+ \- I8 J" \ _7 |0 xcEnable: "event.rc= true;" } );
2 H* j& t& e G2 @ U8 Z1 I4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
- z. {3 X: l- K: y5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
. }4 P& u6 d1 E5 D. Y( o7 ~9 c1 r( ^ l; q1 x
& f0 ^6 t ~2 b8 L N4 w4 t本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|