TA的每日心情 | 奋斗 昨天 10:28 |
---|
签到天数: 2370 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
% J% t# z; |4 A1 R" j1、打开编辑的首选项项& m" F9 r3 f+ k, c" m. g8 i$ Y
+ n! c- t. M! d! W9 }; V3 o
2、确保下面的选项都被选中- D# L$ m7 z) B3 V: S" {7 H
0 s- L6 ?9 b( K+ {
3 把下面的代码保存为一个bookmark_page.js文件
2 a* @- t. W8 z4 P5 j9 O& l. h// bookmark_page.js, ver. 1.0
2 P# Z! o U1 Z9 Q) ?// visit: www.pdfhacks.com/bookmark_page/! h+ H8 }5 P* ~9 }1 K
// edit:cjs 2008-02-17 7 X( f; m, L3 B8 H/ S- g( l
// 1 修改为中文标签
9 }( H4 e. l( ?. b" B B4 e// 2 设置书签时可以自动获取当前的书名2 G5 n( J4 y: r. H, C* U: k
// 3 自动获取当前所在的页码与总页数,方便查阅
~: p, `3 [+ @) s// 4 实现更多功能可以参看Adobe Reader的SDK) W+ W! |% x9 h: N9 Z; M
) t' Q/ _5 K$ i# C, d; E// use this delimiter for serializing our array
" T( o6 t; Z( }var bp_delim= '%#%#';/ {# v# S: b6 O: X! n! ~. K
function SaveData( data ) ...{
7 A* C1 n6 {/ I: C, D0 d. H) U // data is an array of arrays that needs
- a$ c% C6 L, L" k' v. ] ? // to be serialized and stored into a persistent/ l3 J* A% ?8 O6 c0 Z
// global string" {, e8 t! a; M" C' z
var ds= '';
& A- r( K8 c; y; E( x for( ii= 0; ii< data.length; ++ii ) ...{( |6 }1 H! B. v* I1 }
for( jj= 0; jj< 3; ++jj ) ...{
4 V- b/ v0 N+ p Z* h if( ii!= 0 || jj!= 0 )
# m8 @9 {6 q# `4 A& h' c ds+= bp_delim;
5 Z% _3 O( x" h+ Q* W ds+= data[ii][jj];- n& F% r" t3 J% u9 v% y
}4 k( X: M! a) }! {, e& `! o
}$ O0 S# Y# P( ?
global.pdf_hacks_js_bookmarks= ds;0 Z2 a$ O6 y( y" W& Z+ C8 ~" P
global.setPersistent( "pdf_hacks_js_bookmarks", true );
( R3 A. c) a8 V$ B, `. S/ B}
. U5 S2 d- R, ^& u9 E p! N3 _function GetData() ...{$ D& u; i# ~; j9 o2 m# k
// reverse of SaveData; return an array of arrays
5 ~: v8 e. K' l1 G4 ]! f- v: ?# d if( global.pdf_hacks_js_bookmarks== null ) ...{
/ w$ G2 |$ n8 O) X/ b& \5 F; O+ L return new Array(0);" |" w9 ~7 ? [2 f
}
6 a" P# x/ s. `+ N `( W. S var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
! T- {5 y) W! ]5 @* Y. e) \# H var data= new Array();2 y" g: B$ w6 y) v) u# g) c5 `- d* S
for( ii= 0; ii< flat.length; ) ...{' |5 |! e. D) W: k% \
var record= new Array();/ k! ]! `3 |# `. n3 g: G
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{0 ]' X( T0 J4 [
record.push( flat[ii] );) y4 \& i. U" F: T- v0 E
}: A* N/ O4 i* \$ n
if( record.length== 3 ) ...{! u; ]0 E, u8 ~
data.push( record );
) H5 c; R3 ^+ s! F }
" }4 D/ A( Y. E0 l$ x" h }
& F; K0 t8 K. |+ ]/ E- P return data;
" B; K5 f) H( W& w* y5 M}" D1 Q0 h' ]1 y
//Get Current Date# t, Y$ l8 V4 x0 g( n) f; e
function DateNow()...{4 ^0 C) m8 y7 I" u
var d, s ;
/ Q/ O0 [. _0 s' V9 G d = new Date();
) @% R$ J) ~2 b2 ^/ h x, O s = d.getFullYear()+"/"; o/ x8 ~" P9 |4 ^- G
s += (d.getMonth() + 1) + "/";
3 Z' |, S& t6 l+ w0 Z) d! T s += d.getDate() ;
# }# h7 r5 }. H, e7 ^7 f: Y /**//*
4 c! d% u5 J( u0 g& Z# @, X! t s += d.getHours() + ":";
- k9 ?8 S3 ^! s- _* K# x: ]( ^ s += d.getMinutes() + ":";. j4 Q3 `7 @ k$ P! ]! O
s += d.getSeconds() ;
+ Q, g" z% m8 O2 f; D/ X8 z$ r */& ], R; O7 |4 F2 k& o
return(s);
7 E" R! N8 \: p7 M* Q/ s$ [2 g; S}/ ~ ^& H) w6 Z ]0 e
$ P/ V" _( s* D8 K3 q0 s* p5 Zfunction AddBookmark() ...{
, m7 }& A: t# V // query the user for a name, and then combine it with
% G9 x: v& t! a" K; I3 E* H" r // the current PDF page to create a record; store this record
1 M" L2 S: @- Q' k' ?) J9 X var thisfilename=this.documentFileName;0 O! {& \% w6 R3 O& Y, O+ \: [
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));, ~5 }5 E2 P/ h7 j: s
var numPlugInss=this.pageNum+1;
1 N, a8 J, Z! v7 H var currentdate=DateNow();
+ q' D% P: @# C# ~, a, ^ var label=
6 F# T8 O6 E) I7 ?1 D app.response( "书签名称,可以修改以便于记忆:",5 y4 F( ^* [1 r4 m
"书签名称"," `/ p% h6 p/ C( U
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
; M3 t f: o" T4 o false );; H+ I5 N1 \( D8 m/ D& G
if( label!= null ) ...{
+ }* M( g# Y0 U1 y1 U0 v# j* @* @ var record= new Array(3);3 T, O; {3 s, p- h/ ~+ f, v
record[0]= label;/ }) Q0 j3 `2 }$ ^
record[1]= this.path;
% [4 [9 C1 Q+ X record[2]= this.pageNum;
. T, @3 H+ v% Q4 V8 j data= GetData();' A" L% u# D- {
data.push( record );; d7 W8 _3 s6 v% |2 c
SaveData( data );# e3 O3 K; s* I# }% v; y
}2 ?% m: N1 U& }9 u& U
}0 ]; C9 `( M* L2 D0 z
function ShowBookmarks() ...{; l; K( u2 C1 X2 H! e- j) k
// show a pop-up menu; this seems to only work when
* Q3 @9 g% H5 ~. w3 g // a PDF is alreay in the viewer;& u& A- _5 M/ ^+ K0 x T
var data= GetData();1 F: c8 y3 \5 a1 X C) X
var items= '';
5 c4 L) m, b" y9 {* ?4 o for( ii= 0; ii< data.length; ++ii ) ...{+ v2 G6 _1 I+ W
if( ii!= 0 )
+ @! W5 D1 Z8 v# y2 e# Z8 M items+= ', ';) Y3 K+ g: J2 `4 V1 I
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
$ |4 V; E: P u }
" k0 y2 d9 f: u! z7 w- s // assemble the command and the execute it with eval()
; z& q, w/ r8 [; {6 O var command= 'app.popUpMenu( '+ items+ ' );'; x3 c; H7 X' v1 T3 S
var selection= eval( command );& d P6 j* \( y; G1 N5 A
if( selection== null ) ...{9 z# w' g: S' r8 G0 D- u
return; // exit! l8 g9 q$ v4 @0 v
}+ j W( l h" ^# T* u$ L
// the user made a selection; parse out its index and use it
2 E* d! e0 q: N" v! | // to access the bookmark record
/ \: n' ~& e& {0 I: T' F8 h$ w/ \ var index= 0;
1 d# h& p& g; Y // toString() converts the String object to a string literal
4 m; b/ E6 t/ T( a/ Q; C // eval() converts the string literal to a number
* j( q/ g# Y$ ~ index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );) W2 k3 ]2 I% t. [0 s5 o
if( index< data.length ) ...{0 |' M8 z. A! s7 `3 y
try ...{
( I7 x% r n' I- O- V+ @( p& F // the document must be 'disclosed' for us to have any access6 w4 F6 t0 o! v! M4 y/ S
// to its properties, so we use these FirstPage NextPage calls
/ V. k! X: |4 F) [' P; M //; y( p6 f/ F4 y
app.openDoc( data[index][1] );
* a8 G# \1 a) o8 G+ }9 \3 x; K app.execMenuItem( "FirstPage" );
" i: D9 T4 F8 u! ~2 o/ U0 v2 x: s/ P3 A for( ii= 0; ii< data[index][2]; ++ii ) ...{
f& o; W' n$ U9 ^ app.execMenuItem( "NextPage" );
5 F5 y# k6 p" C8 t }' {$ a. @' x4 G) E; M& i; L% K
}+ r' R" y: a Q5 d; i) {6 V
catch( ee ) ...{8 C) m/ ]/ O6 z N1 L, l
var response= . m& N) o/ `8 e7 `! \/ O: Z3 j, n
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");
& r' C" v8 E8 ^" A6 p if( response== 4 && index< data.length ) ...{
, f! G' w7 B0 ^2 t2 x& }, Q; S data.splice( index, 1 );( I+ M1 U7 R! B* V' X: Z0 M+ t
SaveData( data );
4 I/ R; Q6 J9 j1 k+ j+ b }* [) J0 s3 P3 [5 R' @4 [' x
}
: {2 p* M! l& _) J+ t, K$ J }
3 E4 s. ~' U, h, o. N}
* l0 X0 e0 o- B4 W% zfunction DropBookmark() ...{
9 K- Q- {( K$ f // modelled after ShowBookmarks()( g1 T8 i w4 N/ i# j
var data= GetData();
: h4 _/ T/ {' s; N6 h, j1 v var items= '';
& b) e3 O/ D4 }3 Y7 I for( ii= 0; ii< data.length; ++ii ) ...{
* V" D/ g& E& h" U# z if( ii!= 0 ), w2 P5 q, {9 J6 b% N/ k+ T
items+= ', ';
# X; u+ \) A! w; E% \' O items+= '"'+ ii+ ': '+ data[ii][0]+ '"';1 ] h( A( n8 }: C
}: i5 \0 u) l+ n) q( n
var command= 'app.popUpMenu( '+ items+ ' );';9 a/ }, F% J4 t9 p# }
var selection= eval( command );1 d" v4 p2 o" o2 p' u8 o
if( selection== null ) ...{
2 S4 v" m4 j6 r return; // exit
% c$ Z( p: i# f }
& Z( k- `" y% n# k4 B0 i( I var index= 0;, _$ D, P2 H/ X
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
5 d- S; p3 I, v0 S if( index< data.length ) ...{
1 K' P- X' _* h- n+ F8 Q data.splice( index, 1 );
, h# C0 g8 I' @, n8 R9 S SaveData( data );! X& o2 `3 f8 p% _, Z! F, c
}
& Z" l$ R9 H) P8 [4 Q5 g! I}3 y+ F: u, Z9 ]# G
function ClearBookmarks() ...{
' A* M9 x* I/ D7 S. }' @ if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
7 S, k0 T. e; c* \+ s8 v+ n) L SaveData( new Array(0) );( s( U) k$ y" k0 u( ?: ?6 K& L- r" m
}! X% O6 d, p+ |& v
}, ^% p5 u) H; ]
app.addMenuItem( ...{9 B" Y3 N3 `+ G Q
cName: "-", // menu divider
* y h e. a7 ScParent: "View", // append to the View menu
/ n6 `& g N; G# h) V3 j% h9 u1 @cExec: "void(0);" } );' V! A# h$ y& ?: t) U$ p% {) {
app.addMenuItem( ...{0 E0 M& z4 I6 a, ~' \6 l
cName: "设置本页为书签(&B)",2 `4 o- G. Q( p+ {# m2 |( F
cParent: "View",& N0 f! v1 G& p' n5 c7 K' P
cExec: "AddBookmark();",9 i% V6 E+ }, l- m" v
cEnable: "event.rc= (event.target != null);" } );$ ^; O) e o) k9 v
app.addMenuItem( ...{1 Y2 c! {6 v3 ?4 z
cName: "转到指定书签(&T)",' x9 v4 B: C3 Q+ l
cParent: "View",/ w( T3 O7 {5 T" s8 N6 z) N, P
cExec: "ShowBookmarks();",
& a; e) d5 M' N( d" `9 T: lcEnable: "event.rc= (event.target != null);" } );3 d, v! z8 B) u8 h
//cEnable: "event.rc= true;" } );
8 i- j' a- ?- R$ Dapp.addMenuItem( ...{7 t% n `$ \* r9 L5 V) o) R2 W) ], u
cName: "删除一个书签(&D)",
% u; y. r8 ~6 f) m) YcParent: "View",( O8 t* H3 b- ` t3 o9 S
cExec: "DropBookmark();",
: C& {. F( l. B5 b. a! D8 lcEnable: "event.rc= (event.target != null);" } );
$ N1 p2 s/ u! `* H8 U% bapp.addMenuItem( ...{
' [0 J* f J, CcName: "清除所有书签(&C)",
) l3 T ~4 f) a% C8 b- ?1 kcParent: "View",; h4 t) b% H; e% b3 H( s$ Z
cExec: "ClearBookmarks();",
@6 J+ Z3 S& gcEnable: "event.rc= true;" } );6 z8 t" j9 Y) M- K# D
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
4 W; h8 a' y, m% I6 `/ K5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了) v4 N, j6 X2 Q
" @9 s: A2 A9 G* h4 n" b4 _
( k+ L m# \4 T$ z! l
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|