TA的每日心情 | 擦汗 昨天 09:05 |
---|
签到天数: 2402 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法$ j' c F( Y# z
1、打开编辑的首选项项 J& Y( U# J3 q8 n4 L; @. s; C
" f8 O- V5 [# F; a3 N7 R
2、确保下面的选项都被选中% n: D# Q8 b; i- t1 \+ Q
4 N4 E: n" Q: {! ^6 Y8 t
3 把下面的代码保存为一个bookmark_page.js文件
* X9 p: ?" L: f4 u. N// bookmark_page.js, ver. 1.0* a/ y, W' d. S
// visit: www.pdfhacks.com/bookmark_page/
( Z+ h7 K8 H, q6 R+ A! m3 [// edit:cjs 2008-02-17
$ t6 t% K0 ~( u( s, k# ?// 1 修改为中文标签
& X" O( C4 q$ B- ?8 f" B// 2 设置书签时可以自动获取当前的书名
9 d2 s" e+ K: t% V* z7 k4 D3 A# Z- P9 ]// 3 自动获取当前所在的页码与总页数,方便查阅
5 h4 \! W4 n4 V4 Y3 }// 4 实现更多功能可以参看Adobe Reader的SDK
3 a2 D- z# t& P H! y' ?# ?( I# t
) A* ]# h+ Q2 n9 p6 y0 c3 d// use this delimiter for serializing our array6 X4 L7 g' S" C0 p, S+ U/ V
var bp_delim= '%#%#';
7 f' b0 ~0 e# n! }$ ~/ t' ]/ Pfunction SaveData( data ) ...{" P4 B4 @% Z" m% \
// data is an array of arrays that needs# {1 m1 }1 Z2 ^, d8 |+ C# ?
// to be serialized and stored into a persistent
. L$ G( ]& k, t2 m6 ^) m // global string, H3 t& z/ Y, T* s
var ds= '';
" B- D( K! L7 J4 m/ [* c. n for( ii= 0; ii< data.length; ++ii ) ...{5 f; D1 c. m/ b9 Y& G
for( jj= 0; jj< 3; ++jj ) ...{
! w0 B3 C3 S5 @& r) C if( ii!= 0 || jj!= 0 )1 w" ^0 M _/ i
ds+= bp_delim;$ u- u8 X; v# M$ W
ds+= data[ii][jj];
7 \+ w N+ v& y ]0 A1 O3 W }
# V( H, C0 @. {! k; G } W% `* |% r7 R* d
global.pdf_hacks_js_bookmarks= ds;
1 x s& X% z4 J/ K0 s. H$ f) V global.setPersistent( "pdf_hacks_js_bookmarks", true );* D, N0 m$ _4 a2 V
}5 }* q+ c4 P0 ~ J* A9 E
function GetData() ...{" |+ {; ~# p! W, X
// reverse of SaveData; return an array of arrays
f9 O& I# ?# x) k7 F% k if( global.pdf_hacks_js_bookmarks== null ) ...{0 t( e9 x* c' y$ H2 G( t
return new Array(0);
4 u. B: w ~- C+ ]3 ^# f }. R, ]! R7 X5 v; ^& f! M
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
/ |9 f& X+ |& _ var data= new Array();
( F9 S$ _7 ?) Q- w) E. ^9 { for( ii= 0; ii< flat.length; ) ...{
+ v# ]! F z/ P; l, ]4 W, R- C var record= new Array();
D6 E9 g6 |3 ]4 | for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
) D4 V- G* r- \0 R, A6 p, K record.push( flat[ii] );
# {" E8 k0 Y, z$ _. J: P6 _ }
& P3 v7 b: L- ~/ |8 t if( record.length== 3 ) ...{ v8 J6 V9 `- i# y# S7 w; {' U4 T
data.push( record );
1 o6 k0 B/ y; F5 _9 B# p7 Q7 H, A }% G2 }% k; @, q+ ?7 P8 N- ~$ I
}1 `; @3 @5 \' l7 k k$ {
return data;
+ B7 ]. A( }, B}! D, U: ^2 z9 h
//Get Current Date! [% B; I7 j4 q
function DateNow()...{
' j1 \+ h9 r1 K# } var d, s ;: J0 ^0 X% }6 A) v6 x; I7 o4 s
d = new Date();4 m3 J: G' [ a" E1 ~% o
s = d.getFullYear()+"/";
; G' x; R I" V0 J Z( H s += (d.getMonth() + 1) + "/";
$ S: K, V, x; i# g% T s += d.getDate() ;
# w& Z/ I$ q V3 f9 t1 [ /**//*7 F& ~7 p6 F# ^% z5 h- J/ c# }
s += d.getHours() + ":";: a7 h! R0 g6 F# ?
s += d.getMinutes() + ":";% \6 y4 W+ `+ A2 ~/ _
s += d.getSeconds() ;" X4 E* A' t% A0 _8 n
*/4 u: }& k7 P* s* C3 I. _
return(s);
2 U1 w: B( A$ }/ }2 I}
9 |5 H g: h4 {2 e8 ^
- K, W9 o2 n j: ~: B; bfunction AddBookmark() ...{
9 @! @9 T; A0 [2 {" J, X" {( c4 C& }- j // query the user for a name, and then combine it with
5 I2 [1 @, ~1 D5 S! _5 G6 t- a // the current PDF page to create a record; store this record1 i* L8 S$ T- g2 t. o
var thisfilename=this.documentFileName;( o* f* Q% B$ k6 G; z5 \. ?9 u
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));7 n: t( _- T( b {1 J2 _" }
var numPlugInss=this.pageNum+1;; i2 K9 \. z3 G$ u
var currentdate=DateNow();
T$ w' e$ i* P- \& X. F var label=
5 _3 o" |( T; Y9 @- D# r$ q! f app.response( "书签名称,可以修改以便于记忆:",' q0 B: t$ L$ L, N( Y
"书签名称",
) d1 a& x5 f- F "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
1 k# M1 X! B9 f, k4 x& \0 P false );' G2 ]% ]8 t$ W8 j2 a! U
if( label!= null ) ...{- u5 E( o: h; R t
var record= new Array(3);
( G, V4 Q4 p9 |4 L5 L" A record[0]= label;8 H4 j+ ?" k) P. n$ \6 Q
record[1]= this.path;/ U. t! ?* z# w3 I- ~+ r
record[2]= this.pageNum;, y1 c/ A- Q8 s* {
data= GetData();
N+ o6 P8 u. W. B data.push( record );9 A4 O( K6 \4 L$ M* [
SaveData( data );
g6 m. e `5 [3 Z5 d) d% N' x }* P% `% p# H! `% H: D2 _' U
}
' I+ {5 c4 G) {* lfunction ShowBookmarks() ...{9 c* P6 Y% T, I' b6 ]
// show a pop-up menu; this seems to only work when: Z0 F* s8 D- \$ g4 M; H
// a PDF is alreay in the viewer;
8 Q( v- c4 S u" K4 o( B- W, o" J var data= GetData();% h3 g; c/ S. N3 n3 Z
var items= '';
2 _ T1 p9 [4 N& d* |9 c1 v5 M for( ii= 0; ii< data.length; ++ii ) ...{ P- y7 B8 }2 ~' u5 F, W, K% S
if( ii!= 0 )
! h9 Y& Q4 z, D, T3 C items+= ', ';- R& c( y' ^ K. \; Y" t* _& D$ n
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';# H$ y Y+ _$ t2 C, v/ @
}
4 E6 V, {0 M5 H- s // assemble the command and the execute it with eval()/ r3 q* r2 Z# u, ]
var command= 'app.popUpMenu( '+ items+ ' );';
2 D3 c# q) p1 [- t5 @4 @ var selection= eval( command );* V. E% a7 C0 q1 t9 A- {9 n
if( selection== null ) ...{) }1 C4 D3 ~! t7 z6 j+ r+ O
return; // exit+ A. P: P/ b! P# |9 I, I# [7 g% A* G
}
! {6 o5 z2 Y8 Q2 ~5 x6 m2 ~ // the user made a selection; parse out its index and use it% S. D/ e& T& J0 V {' U8 {. U( \* l
// to access the bookmark record
' \- B9 L! q! Y% x! [ var index= 0;
# N3 z/ j$ G+ M3 Q$ A4 V // toString() converts the String object to a string literal
* E& M$ }2 `' M // eval() converts the string literal to a number0 {" q3 F& q' g( L
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
8 Y9 i9 c v( ^0 ]; v1 @ if( index< data.length ) ...{2 g/ |5 H+ w4 ]/ Q% R
try ...{
( v8 N/ ]4 P% i* @! w6 c6 ? // the document must be 'disclosed' for us to have any access
+ J, S0 `4 k% t' Q // to its properties, so we use these FirstPage NextPage calls
; r" g4 R) J j. j, H. w //
' e: v5 g# Y. J* z app.openDoc( data[index][1] );
/ R- v3 N, J0 } {; P app.execMenuItem( "FirstPage" );$ |4 L% e6 }& u+ ^+ ~
for( ii= 0; ii< data[index][2]; ++ii ) ...{: J. m; [- x# D8 [4 p- l
app.execMenuItem( "NextPage" );
$ A6 h" N. j0 n$ k" S }
; ~8 u1 k: h- { }7 l" F3 `$ g( g( U3 Y$ p% \& q
catch( ee ) ...{
" F, s1 _# x. }: ]: m/ R" E" v var response= , q- j0 R# L; Z( U/ k
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");- [) D, P& f4 x- c& r
if( response== 4 && index< data.length ) ...{, s' v: e* d5 v; J% Z6 J0 ~
data.splice( index, 1 );' K P5 r! e5 A% q6 Z2 b3 o
SaveData( data );
/ H1 V) G- O3 o A! u }
9 P, M! z- H' q9 \# U& N }
2 Q7 p; _& @$ c' m: R6 x, Y9 Y# Z }! i/ y' D# _2 \- U. l
}$ r& l9 \ ?" ^4 x, }- q: t
function DropBookmark() ...{ e( O1 I9 @& [5 Y2 f
// modelled after ShowBookmarks()
8 N$ w; J# V6 t! v6 ~; \0 E. M; R, p var data= GetData();, x, Y9 p2 G, Y1 @& m
var items= '';- H3 f X4 A2 f+ s( T+ r
for( ii= 0; ii< data.length; ++ii ) ...{
: a! ~3 j/ V O+ U, r6 S$ w$ m if( ii!= 0 )
) l5 c: g2 l9 h3 t# r( L3 R items+= ', ';! u% E8 u% Q0 A" C- }+ D& }) ^; V
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
4 |5 Q' J* v' s/ k1 J- Q) l2 b }$ O# o6 ~2 `7 k
var command= 'app.popUpMenu( '+ items+ ' );';
- O C/ F$ N% @, i& A var selection= eval( command );
* B1 K# t8 ~' _, @8 l5 I3 ~5 W. e if( selection== null ) ...{
& [" O8 [8 p9 T+ z3 t7 t return; // exit
1 [5 B6 b2 W: Z6 F }6 m9 }5 h1 B& F+ T+ L- U! v
var index= 0;
" K7 H* n6 R* U; t$ v, Y+ k& M1 C index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
' Q0 q% _" o: e( W1 A if( index< data.length ) ...{: {8 W, x3 I, e# n! b
data.splice( index, 1 );
2 {2 a3 f/ |7 y# E SaveData( data );/ f" d$ D0 }. Y; Y$ q# M# i n
}6 K. y0 ~6 }8 ^! h" b; q, Q
}4 b7 W- I+ Q& F. K X" O$ w5 O! }
function ClearBookmarks() ...{. M1 @/ Q I0 E- a2 b
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{* g. u& a, X; g+ a, O
SaveData( new Array(0) );$ j- }5 V) r, e2 A- ^/ w8 j; f
}
' R9 \0 F+ M# q! `5 f}
& ?' r( m! q* B4 h& y3 yapp.addMenuItem( ...{
5 }" h0 ?- G0 z0 jcName: "-", // menu divider
8 D: o1 A" C9 S/ @0 |& [cParent: "View", // append to the View menu
) a4 p3 Y9 h' ^- O6 U$ GcExec: "void(0);" } );
* j6 g9 j2 E; Z/ P0 O9 f8 w; d9 vapp.addMenuItem( ...{0 \4 j" ~4 ~5 u" d. D. v
cName: "设置本页为书签(&B)",! R3 t9 I/ t* Z' p x
cParent: "View",$ x0 D: ~' Z# O! n: Y; s' O
cExec: "AddBookmark();",
8 b' H8 S l: O/ q; zcEnable: "event.rc= (event.target != null);" } );
2 T5 j% ~" c3 O# i, Q* l9 happ.addMenuItem( ...{
) Z( F# w, Y( t8 g0 f; _) EcName: "转到指定书签(&T)",
& a8 D9 q1 t) K( r3 \# UcParent: "View",8 h8 ~# _) E* V: C- A( ~% w) B& H
cExec: "ShowBookmarks();",: K" W# A* n5 h9 w8 v$ J/ q
cEnable: "event.rc= (event.target != null);" } );
+ ^' Q6 ^( I! t9 @4 Z) ]//cEnable: "event.rc= true;" } );% z! i" a7 h4 V, d& _& u( G
app.addMenuItem( ...{
) F2 K) D# Y, r6 hcName: "删除一个书签(&D)",9 h! n9 Y$ k8 F
cParent: "View",% c0 o8 E0 `* g5 j- M
cExec: "DropBookmark();",+ m' v9 J2 a- J7 [0 J: q* }; O
cEnable: "event.rc= (event.target != null);" } );( H: P6 O1 {8 a" U) H
app.addMenuItem( ...{+ X8 [) f' C6 X; U* i
cName: "清除所有书签(&C)",; R) U4 n& M7 P' M) n, h0 D7 Y
cParent: "View",
5 n4 _( M+ [, \; ucExec: "ClearBookmarks();",
# Y& ?, n) X0 vcEnable: "event.rc= true;" } );
5 m' w/ j: Z# ]4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下# H0 Y n/ g: i4 C+ H
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
7 }2 D+ P' I0 G q4 e
. b0 E( A# {$ Z+ S5 X6 q* U9 Z, M2 C5 h3 r) K" ^
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|