TA的每日心情 | 奋斗 3 小时前 |
---|
签到天数: 2394 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法' s7 w! E$ |5 T' _5 f
1、打开编辑的首选项项6 P' M- |" r$ [- }7 S
8 ?6 l4 d& O- p8 [/ {& B; J' N' A# d! l
2、确保下面的选项都被选中
6 F5 G# f0 Z9 }& N! o& k4 T
; ]& ]* _, E% _$ |; f8 Z* [( r$ B3 把下面的代码保存为一个bookmark_page.js文件+ v$ }( _- ^9 A5 i$ z; p. E
// bookmark_page.js, ver. 1.0; E' K3 |5 m: T" d( x A
// visit: www.pdfhacks.com/bookmark_page/
# x3 R6 J% |! R. r, H// edit:cjs 2008-02-17
5 h& t+ l/ X- E// 1 修改为中文标签
5 a e" M( i; O4 Y6 @// 2 设置书签时可以自动获取当前的书名) N- |" o6 r1 ]' F( l' L6 C
// 3 自动获取当前所在的页码与总页数,方便查阅
5 F( C% c) r$ ]* p: |3 h// 4 实现更多功能可以参看Adobe Reader的SDK+ k4 D1 ^+ Q$ v
( V1 y, u( W- }" ?; \. h
// use this delimiter for serializing our array+ s& _3 V; e( q+ ~# n& L' E6 ~
var bp_delim= '%#%#';& ]4 d1 Z; p; L' ^
function SaveData( data ) ...{2 |( f4 _8 O8 u
// data is an array of arrays that needs
5 }# [; N- C5 |' W1 N: F // to be serialized and stored into a persistent/ D8 Y- a" y% z4 J
// global string
+ f8 K$ F/ Y; k var ds= '';# z6 E! L1 y7 R
for( ii= 0; ii< data.length; ++ii ) ...{
2 o! _3 k4 A7 n: Z0 _4 s' U for( jj= 0; jj< 3; ++jj ) ...{
- J8 ^6 A9 p( D' d9 V. h if( ii!= 0 || jj!= 0 ): Z$ C" s1 m* K/ H2 F* V- W+ r
ds+= bp_delim; `4 B# I% n5 W# g
ds+= data[ii][jj];6 E. `: O) e1 W( N0 O; K$ V9 R6 |0 r
}
& ^; `- w1 x: h6 e) T }4 B x1 G, d6 f5 e
global.pdf_hacks_js_bookmarks= ds;
& q5 D* G- l0 [5 O global.setPersistent( "pdf_hacks_js_bookmarks", true );
+ v! J6 N6 C7 Q* V" j}8 N6 ~' }, M7 C* G0 q, t) [0 e
function GetData() ...{6 ~! O/ w- E' ~6 h# ~8 U- a
// reverse of SaveData; return an array of arrays
* X X9 `3 H8 Y if( global.pdf_hacks_js_bookmarks== null ) ...{! V; b5 E& B& o8 f+ i U8 w
return new Array(0);
6 k( N3 `3 {/ T- d: c! k' _$ R+ a* ] }
1 I' C x& o" c* [2 \ var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );* w% R: ]3 f9 L4 R; P( g2 y1 M
var data= new Array();
$ {: J+ p% F+ a! r8 H5 } for( ii= 0; ii< flat.length; ) ...{
. S- k( w ^; d5 J" K/ e+ o! L var record= new Array();' ^% P# ?; ~. Q* \( }! p6 I
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
6 t, `+ _3 W" ?- ^% O' l record.push( flat[ii] );. f( Y1 b. c* a% u6 Q
}
1 y% c4 @8 n! Q if( record.length== 3 ) ...{
/ N l& V, I2 Y1 O9 ?) a data.push( record );; n6 T/ E+ }# s; N6 e. g& N
}
* j1 t9 `. l% `' O% D }
, A% ]9 P' _4 I0 L k; X return data;
. v& L% q3 O+ v6 r% o$ q+ j}
9 b' ]$ s( U$ u: J' u$ t//Get Current Date( z& o+ E4 k' b# v, ^" b
function DateNow()...{" L/ m, C1 @2 `: { p/ p7 s
var d, s ;4 ^/ N/ ?. F u$ j" t
d = new Date();
" l& ~: F `- s1 ^2 r s = d.getFullYear()+"/";; c! ^4 J& P3 e/ r$ G
s += (d.getMonth() + 1) + "/";; C2 K4 ]8 H8 c9 S4 Z% d
s += d.getDate() ;
; ^' c1 C+ c5 \/ \& u /**//*- ~7 F$ h1 W9 B3 Y+ `
s += d.getHours() + ":";% B0 X1 a$ h* N; x T7 Q0 q: @1 |9 X
s += d.getMinutes() + ":";
/ Q8 E* g1 e# @9 @- ?9 H1 R ] s += d.getSeconds() ;3 P: W3 X& C+ n4 z" X# C" u. y
*/4 X! a4 j) Z3 p) @0 u7 a3 e8 ~
return(s);
' {+ |8 C4 h8 ~. A; Z6 d}7 ?* o% J+ ^( {+ @6 w/ m
6 k/ o* e1 T7 U$ i+ cfunction AddBookmark() ...{
3 {$ ^2 X& k2 M2 m/ s1 c // query the user for a name, and then combine it with7 ], {7 X; I3 n5 a
// the current PDF page to create a record; store this record
0 V4 L ]2 E7 d3 r7 K/ M( G4 y1 w var thisfilename=this.documentFileName;; z/ m3 [% I" I/ G
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));* {! @9 Q- W: o
var numPlugInss=this.pageNum+1;2 _( u8 D: i$ T7 x
var currentdate=DateNow();
$ Q8 r/ M" [; b+ L; M2 n% h3 ^ Z var label= & q2 w$ M; ^$ f9 y) t
app.response( "书签名称,可以修改以便于记忆:",
1 o8 o9 \+ x7 I9 f: S; j7 | "书签名称",. T) Y! E8 i: U$ K3 B8 J
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,6 {. s' E" B! r8 z$ Z6 z$ Z8 q
false );8 K+ i5 u ~9 ?! V8 `
if( label!= null ) ...{, ?- l$ S3 G8 W; p( t; X! T6 Q, }
var record= new Array(3);# l9 X8 x3 a% h0 I$ a
record[0]= label;8 M \( L0 I1 f# E: b2 t/ A
record[1]= this.path; z8 J+ E$ |* U' \. s
record[2]= this.pageNum;
7 N4 H( N: j# G7 D3 F7 q) i data= GetData();& ~3 R8 w& X b+ N& z
data.push( record );1 N7 {- E. I, x* D
SaveData( data );
- x) {8 b1 Y B$ ~- J& y }) R6 R; ~4 H9 B) ]9 q
}
) m- S4 w( ]+ F; U8 yfunction ShowBookmarks() ...{
1 L7 w4 e" B+ _$ O# g- o // show a pop-up menu; this seems to only work when
2 p; _, e- @& {0 }8 e, ` // a PDF is alreay in the viewer;7 m8 a1 N: N9 a
var data= GetData();% X1 ~. h/ Z' b& s/ X$ J
var items= '';
3 w4 w# t- F/ q l: _ for( ii= 0; ii< data.length; ++ii ) ...{
7 |" I* o" T8 k( j if( ii!= 0 )1 _, f6 _& c8 O/ s3 y" y
items+= ', ';
x1 W( E3 @ S; |5 G items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
, {/ r7 d+ i. ^1 h; I$ l, { }6 [6 Q* y' m D2 R
// assemble the command and the execute it with eval()2 E6 W5 p$ O" w
var command= 'app.popUpMenu( '+ items+ ' );';8 [7 i# d& i$ Q
var selection= eval( command );" E; }# w6 q5 `0 r" D$ ^0 p$ ~" c
if( selection== null ) ...{
$ R* z& N- Y; y( v return; // exit
9 B+ D" M* c% t8 z, Z }! E) G; D3 b7 [& @ S+ ]
// the user made a selection; parse out its index and use it
' a0 n0 }# G! ^$ ^8 c, G // to access the bookmark record1 y7 m% h0 P9 O1 h+ t
var index= 0;8 b$ X$ I8 e' ?' M* Q' Q/ l
// toString() converts the String object to a string literal
$ v2 Z" @) o2 X& } // eval() converts the string literal to a number# R# Y5 J5 m% r3 y
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
* Q+ g# D+ P& K; ~( b- F if( index< data.length ) ...{2 k# R6 w) D& }/ h8 l+ a7 X. S7 `
try ...{: t5 L6 w s# q0 n7 C- z9 Y
// the document must be 'disclosed' for us to have any access
4 w3 V/ J2 D7 P" c // to its properties, so we use these FirstPage NextPage calls3 @# j% H3 G( a- x c
//( Z3 j! Z4 x& H- o8 ~3 p9 }
app.openDoc( data[index][1] );
6 n+ }$ X g4 ?( q app.execMenuItem( "FirstPage" );
) C; i) X3 s: Q5 e3 l9 U for( ii= 0; ii< data[index][2]; ++ii ) ...{) c# q" q2 [' j# m
app.execMenuItem( "NextPage" );" Z( m+ D4 v0 ^# G. h: a8 ~& q! _
}; Z+ K" U) O- x, v& e! r% |# u
}: h6 d8 n; j( e
catch( ee ) ...{0 N, L. v9 J6 [6 o5 m" q5 B0 t; _
var response= ( y9 ?5 s: u% r% O! Q
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签"); s) @0 ]* N, f$ I8 V. B: |
if( response== 4 && index< data.length ) ...{+ o4 N8 ~2 ^7 i( Q+ {
data.splice( index, 1 );
3 i& q- w N$ @8 N8 J SaveData( data );1 `6 j P3 h$ x- e% p
}
+ u9 f) h/ z0 Z3 U* s ` }
4 R# w0 `3 B$ \4 s }
C( `( K2 K3 D8 T: t}
' P5 V, Z y$ y: j3 |/ ^function DropBookmark() ...{
8 J* q) d; j" [2 U // modelled after ShowBookmarks(). l; U. V( {" y+ w( f9 Q
var data= GetData();0 @( W* y4 h0 s
var items= '';! V' D# J. _. O2 T q
for( ii= 0; ii< data.length; ++ii ) ...{) A* X6 b( \5 b R1 E6 v, e9 x
if( ii!= 0 )6 T/ C' g2 X( X0 v" h5 ?
items+= ', ';
# k% v3 n2 ?, O4 x2 U0 i( d items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
1 C1 H2 ~4 V5 A- \3 f; @* I }0 C3 x, P9 z# Z% S. d8 |: P
var command= 'app.popUpMenu( '+ items+ ' );';
^+ N$ f: e4 J; ^' t: o: k var selection= eval( command );
; v% x4 S9 ?; l/ o5 Z I7 e1 E; r if( selection== null ) ...{
& @* S$ j$ c4 _ S: \- @* C8 l return; // exit
+ F$ v2 G) J/ L, @9 ` }5 F$ o2 ^" t, w
var index= 0;
! ?/ f! M* `) ]/ a( y. G+ [ index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
# e' w/ n) i; P/ N3 I4 g: A* k if( index< data.length ) ...{
9 R/ w) t1 U" X4 ^ data.splice( index, 1 );: r$ P$ b# i$ ^7 T# J. C# X% @
SaveData( data );9 E2 Z) f0 A" P+ u' d, \% O6 m
}6 P" R9 f) b. P
}( I# h& S0 G2 V# ?
function ClearBookmarks() ...{
" T$ U$ f2 S. N+ T4 ^ if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
- d3 b) Q& J# T+ v2 w! R SaveData( new Array(0) );/ J# G# D/ v7 ^% D9 v/ o5 H
}
3 e: f6 Q/ ~ ^5 J}
! Y- k2 ]* ]- g3 x" j) Capp.addMenuItem( ...{% o/ w; p' S, f5 @. G
cName: "-", // menu divider# D& J+ L& z* J
cParent: "View", // append to the View menu( W% ]0 q. m! s0 r- x
cExec: "void(0);" } );
3 | w) |% R* ~/ s2 R$ {app.addMenuItem( ...{
5 X- @" n/ u! d' R7 S4 [) KcName: "设置本页为书签(&B)",
2 V7 a0 x9 [( J& q# h( zcParent: "View",4 @8 Y9 l/ T" [6 N6 r2 i& L/ w
cExec: "AddBookmark();",
8 O7 g3 W7 H- V' D0 ScEnable: "event.rc= (event.target != null);" } );
0 o1 Z1 K% G' Y5 A0 wapp.addMenuItem( ...{4 \9 J/ X" h' y0 w. I
cName: "转到指定书签(&T)",
: N: ~6 V# ?, B' J8 G% VcParent: "View",
3 }7 \! V a- _7 n4 @" t0 T! dcExec: "ShowBookmarks();",) w! K) f: e* f+ _/ C: t0 t
cEnable: "event.rc= (event.target != null);" } );# |* }2 e* r; W: ^, D X. e+ T
//cEnable: "event.rc= true;" } );
& ?# F4 ^9 E8 m! o& M6 }& q# T0 _app.addMenuItem( ...{) w K( Y$ K( W9 c% ^
cName: "删除一个书签(&D)",6 `, i2 }6 |% x, s" A/ |) ?
cParent: "View",
% ]8 c4 Z* ~5 a4 S2 rcExec: "DropBookmark();",
2 r! C; N3 r' mcEnable: "event.rc= (event.target != null);" } );
2 ~" u. \0 }% R2 s" o2 b- e8 Dapp.addMenuItem( ...{' u# O$ x( ~% a- F" o s
cName: "清除所有书签(&C)",. m2 K- F( K1 _- |
cParent: "View",
& X0 ~" M2 U6 v3 r8 |cExec: "ClearBookmarks();",* ?+ P% [) t1 U3 |" H% E
cEnable: "event.rc= true;" } );
) i- c' \% H* V4 [2 x4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
5 [& p, m; s& R& ~0 f' m5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
, s: H4 Q2 p% M4 f8 u8 l% M
( Q: m: G# h% h
2 L5 ^- A% } s- _# d本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|