TA的每日心情 | 奋斗 昨天 08:43 |
---|
签到天数: 2391 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
* G7 |+ n0 s0 V$ t0 x" m1、打开编辑的首选项项, H- C& [1 n* C, z( R
" K/ d. E! C- i% k B2、确保下面的选项都被选中" C; n( ^: b* Z
' v3 F. F+ U, s1 ~; k3 把下面的代码保存为一个bookmark_page.js文件
( t7 z' l! N0 P( m// bookmark_page.js, ver. 1.01 s4 O0 w: w2 S. I% N5 F4 D) [
// visit: www.pdfhacks.com/bookmark_page/
8 D4 ~. i& x1 q// edit:cjs 2008-02-17
" z# \ [/ n# t) \, F1 k// 1 修改为中文标签
- p6 e- d( c2 L4 p F' J// 2 设置书签时可以自动获取当前的书名
; w" `( P; H. R( p. L/ K// 3 自动获取当前所在的页码与总页数,方便查阅
! t! S3 @* B% j; }// 4 实现更多功能可以参看Adobe Reader的SDK0 a+ L7 R( w) h5 Q {& y
0 Y7 \! {; E! Y7 c0 q
// use this delimiter for serializing our array
" C" Y( s0 h2 s- c; l+ Ivar bp_delim= '%#%#';
6 s% N8 ?* \9 X- J; H {% bfunction SaveData( data ) ...{3 q4 R$ \- `4 { ~! Z5 B) L6 F
// data is an array of arrays that needs
. U& ] {/ E$ G1 s' i8 k* { // to be serialized and stored into a persistent) H( u6 E9 u) G7 k ^
// global string6 O! p" G9 N! I* I
var ds= '';
. |7 _( D8 {/ E: Y% e) M- S5 s for( ii= 0; ii< data.length; ++ii ) ...{. E7 K2 k4 Z/ x' Q
for( jj= 0; jj< 3; ++jj ) ...{; g. ?- g( Z( k' S
if( ii!= 0 || jj!= 0 )* h3 A9 i3 [7 h7 V, n( _
ds+= bp_delim;" t6 @( U! E$ m# z8 T8 Q
ds+= data[ii][jj];
) k) J5 {& O0 }- |3 V0 x* F4 @1 T }
7 X; e% I* o. I' W3 O5 u' z% f }
( Q2 E8 t+ T/ `) `0 w1 C6 P) O global.pdf_hacks_js_bookmarks= ds;
0 W" ]* W6 M' i: }1 N* ]* C9 s. b global.setPersistent( "pdf_hacks_js_bookmarks", true );
4 K0 R; K, K- c, h! f3 }6 C" R. N}
I+ M+ N- u. S6 jfunction GetData() ...{
4 {6 }* m( E: f4 Y // reverse of SaveData; return an array of arrays3 X" ]7 R& n5 A! N6 [8 O
if( global.pdf_hacks_js_bookmarks== null ) ...{
7 w# {. F9 O5 t+ e( H$ z return new Array(0);0 }* X. J* {6 b, _
}
/ I: d% s: n) L3 h3 P var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
U1 p6 v, G9 I9 l" K+ c3 c4 P var data= new Array();
: @: v1 N; Q4 Q6 D" k+ u7 } for( ii= 0; ii< flat.length; ) ...{
( T/ ^8 i+ ?4 Y8 j& f) Z var record= new Array();
0 n0 a1 k4 ]8 m+ |9 m for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{2 N. ~" q4 D; g. M
record.push( flat[ii] ); w( W/ P8 f0 ?; ~5 U6 ?# p
}, U+ ~3 w5 K8 I# C. c
if( record.length== 3 ) ...{4 R' K( Y6 @+ e; B) s* ]& E0 F; W
data.push( record );, a) B0 V: q7 j$ `% B
}1 f- M" e; ?: Y) K& Q
}
+ ^4 N9 ?. }7 k1 ~ return data;
2 z8 }" ^3 c- z" v) y% k) ^! M}
, a8 a- k2 E& j% H2 D$ p2 V3 W* [//Get Current Date
, j5 E9 a# a& s' ^0 [7 W- mfunction DateNow()...{
& U/ c: g- a+ {3 D7 c9 Q var d, s ; k8 I" F; d8 ^, O% I" W6 x4 u
d = new Date();
! W7 l: L5 n% C# m s = d.getFullYear()+"/";
4 {. u% j1 b2 q+ O7 w s += (d.getMonth() + 1) + "/";! K. ~+ K" p; e) ~5 G, M6 f: y8 Q
s += d.getDate() ;! y9 n3 o( Z- p, S' e/ ]7 E
/**//*
# W f! P. K. i6 p s += d.getHours() + ":";
: X* r0 Y9 n- C& U d+ r* [ s += d.getMinutes() + ":";
- s1 A2 ^5 P& m0 U6 B* e7 S6 x s += d.getSeconds() ;
% `7 W' N( ]7 S+ c0 Z */ G" Q% ]! N) N2 H9 s7 C4 k8 d
return(s);
9 u {/ i+ y9 H, e}
; n3 b- }5 @: x$ k5 e: g* F( U6 C, X/ C5 h U
function AddBookmark() ...{% n \+ `/ T v) O
// query the user for a name, and then combine it with
2 t% E$ w% S5 D% a // the current PDF page to create a record; store this record' ~ z$ P% n, H' O% }& j
var thisfilename=this.documentFileName;
% x6 ^& n( ]% _( z5 \: z3 {( H- ~ thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
, Q7 M8 @) h4 \" \) q1 v var numPlugInss=this.pageNum+1;" Q+ ?& m% M" G+ x8 G* V- \) n( l
var currentdate=DateNow();, C/ ^ [3 _& \2 H
var label=
5 m3 `8 B! N8 \, ]! H$ g app.response( "书签名称,可以修改以便于记忆:",0 U7 l6 }7 h# I7 i4 A
"书签名称",
7 g P2 n( o l: y, i8 y$ X "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
2 B* R$ k: E4 G: n! o! B1 \ false );9 O: F6 o4 Z' F5 l: F8 D7 H
if( label!= null ) ...{8 {3 ^8 M* ]. H4 ?
var record= new Array(3);
0 M- P+ d o; e0 u0 Q" u; } record[0]= label;5 i- A6 B. W0 f( y) [
record[1]= this.path;
, ^% J7 G- p- @8 E6 Z! [5 h! r record[2]= this.pageNum;
6 v1 C; b7 E0 D& l1 U; V/ Y data= GetData();. F- H% S- V; U6 U
data.push( record );+ ]! D3 T, K) w: x
SaveData( data );
9 `+ P- p1 g3 F6 H1 x& b+ F }
6 `8 U/ L0 A! w; `4 b}
: j, G2 U" n6 l6 O% T% cfunction ShowBookmarks() ...{
" d2 d, d) ~4 `5 q# ]- Y; m/ t // show a pop-up menu; this seems to only work when5 t; o" E# T. S0 c3 w5 z$ I& P" v$ |% u
// a PDF is alreay in the viewer;
/ f: D z, I, f; Z1 [4 X var data= GetData();3 s" ~: s) i- K, K' y; A% O8 D
var items= '';
|( B4 r+ W% v, R7 {! t for( ii= 0; ii< data.length; ++ii ) ...{
; ^ F1 E/ h6 \" j+ F if( ii!= 0 )
) r! `8 i$ q" O/ f; {$ F) q items+= ', ';
; S6 G+ D. T1 r1 \4 W items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
; U4 |9 L& n i; T9 y) X0 g7 j }
4 i) {# a& r8 h; ~* L. k // assemble the command and the execute it with eval()' @6 u4 L1 ~! b) A1 S+ u4 x9 V
var command= 'app.popUpMenu( '+ items+ ' );';
! y: O. `# z6 `0 N \ var selection= eval( command );# J6 o, L9 w' D/ H H
if( selection== null ) ...{
' j" D( u2 V9 D+ H& F- ?7 r2 B return; // exit
+ I2 f% k; A- E8 g, P }
, V- E& x8 ~8 B% v+ D7 { // the user made a selection; parse out its index and use it6 H3 c( S- w' \
// to access the bookmark record+ e! c6 }$ R7 r
var index= 0;
( _$ w/ Z/ |7 }. \- P" ] // toString() converts the String object to a string literal6 j- w$ }: _8 v) b( L3 [- P3 E9 F
// eval() converts the string literal to a number8 S4 O1 u: p4 v" }9 S# ~5 B$ x
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
2 R: V* t: h8 @% M( M) M if( index< data.length ) ...{
& U! h# t7 f0 {, v try ...{8 H, j$ `. W% V l
// the document must be 'disclosed' for us to have any access
' Y1 F$ h, V$ Y6 V: Q+ j w4 v // to its properties, so we use these FirstPage NextPage calls/ M2 w0 ~ v. p" D
//* j. {5 E& c: u
app.openDoc( data[index][1] );5 J- S" v- n: h2 o3 K# E: |6 Z
app.execMenuItem( "FirstPage" );" F0 I* ?2 c1 q/ G/ U& D: P) h0 M* r7 S
for( ii= 0; ii< data[index][2]; ++ii ) ...{6 G1 A( s: k8 f* [
app.execMenuItem( "NextPage" );4 H! q! J' j2 w2 n/ P, q, U
}7 g8 r- n- m+ C0 t1 ]
}; p$ k h) J6 V8 c9 U6 L0 @6 \
catch( ee ) ...{, y) u6 B# V n5 }* e: o
var response= \+ x) g+ ^& _+ C% U6 y3 B# b0 Q
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");* X4 s0 F0 f9 N: T
if( response== 4 && index< data.length ) ...{
( J4 T; b8 d" r$ ~ data.splice( index, 1 );
& T6 F8 P5 F' W; I, s- E SaveData( data );+ F7 Q5 J' l. _% G6 @8 G
}, m4 ?9 Y; i! d* p9 Y8 g
}. \; H+ C# n$ ]6 d! U
} h- j. I5 Y! [1 z, C9 F7 U8 p
}( Q' J1 k' O2 n: p7 j
function DropBookmark() ...{7 o3 g7 D/ c7 h9 M- k
// modelled after ShowBookmarks()* a1 v9 T* F9 i1 G' A! D; [
var data= GetData();
, ]6 T2 L; u) k. {; c, K1 r var items= '';* a3 b+ p3 e4 o3 ^1 J8 c6 b
for( ii= 0; ii< data.length; ++ii ) ...{
& w m$ Z' Y1 _1 ?9 I if( ii!= 0 )6 p2 f$ Y: I! j: h. r8 L4 ^
items+= ', ';) g* [ {$ g5 g9 d3 G
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
$ _& O2 X5 r5 f4 x! B }- N+ O, B5 Q3 z& e @ t
var command= 'app.popUpMenu( '+ items+ ' );';
" ~# x* _' ~# Y, i2 K$ q var selection= eval( command );
2 V F& r5 ^+ m% r if( selection== null ) ...{$ v9 Z& x9 m+ c X* @1 t
return; // exit
- Z7 n1 i/ J+ ^ m+ R, ~ }! G0 D6 ?7 R b
var index= 0;
6 ]9 S1 |* E) f) V; p index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );" y! l! G: e; \5 P. n
if( index< data.length ) ...{
: ^7 d/ a, z) N( a1 _ data.splice( index, 1 );
5 N t! \' U9 a' g SaveData( data );
8 x+ m, H) g+ p) L6 S9 }8 a: Y }8 w7 ]0 o' w1 B2 d8 R' y2 ^; d
}) ~) b1 x, ~4 w& Y2 e" i' c
function ClearBookmarks() ...{
! J& m" h8 X% G0 [: A. q0 ^ if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{) `& Y" j; ~9 [; z- b. Y# M% s( k
SaveData( new Array(0) );
0 w; |" o- z, H5 s1 h0 y }
1 ~) t. a! u9 o: n}4 P) N; @/ i8 ^* \) F" o E: m
app.addMenuItem( ...{
6 F$ w" n9 Y" }" a0 `4 ZcName: "-", // menu divider
$ v4 g" h3 @; @3 v( acParent: "View", // append to the View menu
0 g1 Y9 Z5 L# f9 c0 ?8 d3 d+ x. hcExec: "void(0);" } );
9 S A8 o+ R5 c1 Bapp.addMenuItem( ...{
' E1 [( t/ j( `! n# |* vcName: "设置本页为书签(&B)",) m8 y, n# @3 R( v
cParent: "View",7 g( w$ u2 E3 d N; K
cExec: "AddBookmark();",% T# q- g- h1 D8 D4 g$ t0 p9 [
cEnable: "event.rc= (event.target != null);" } );5 ?/ ]8 q. `8 S# A
app.addMenuItem( ...{
( L! x7 ^' ^) I- y3 n/ V$ DcName: "转到指定书签(&T)",
; m* z t" B/ O* Y6 x! J' l3 z) W Y4 s! fcParent: "View",& N$ e# d, ?, A6 x! M: t
cExec: "ShowBookmarks();",7 a- h3 v! S, z9 Y+ q+ p
cEnable: "event.rc= (event.target != null);" } );
$ x3 s6 o1 U% g8 v//cEnable: "event.rc= true;" } );
! z0 y% s* \$ @! H5 y5 ]1 [app.addMenuItem( ...{
0 p* }/ ~( C" @cName: "删除一个书签(&D)",1 h+ l9 @5 q9 |9 k; q* q( B
cParent: "View",
* z F; v' S% W7 H [( McExec: "DropBookmark();",, K, V( T. e& l8 P2 p
cEnable: "event.rc= (event.target != null);" } );% }: | A) B- @3 t4 o& w
app.addMenuItem( ...{ O. e$ H0 j* P; N( f) f
cName: "清除所有书签(&C)",3 Z/ W2 ^( A$ ?. B5 _# K
cParent: "View",( d% t: M2 V# y6 D
cExec: "ClearBookmarks();",
. k( ?: x$ q* X6 ?" T% D7 w8 |cEnable: "event.rc= true;" } );
2 {0 C/ K4 q$ N$ }5 {( S4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下5 a' y3 ~' ]+ r7 P4 t, q% E: h& ^
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了- Q5 }3 ^( U7 q1 A- V2 s
; P6 _* [ m4 H+ ?8 _
1 j/ _. g N5 ~8 E
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|