TA的每日心情 | 奋斗 3 天前 |
---|
签到天数: 2383 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
% u+ l: N4 }" s1、打开编辑的首选项项& v8 Q0 N! a3 E
3 u* @: R- {7 s9 z4 K* T! H+ e2、确保下面的选项都被选中
1 b. V: }' l) x# I5 ]
0 @7 [" _8 \4 ]5 _2 u+ V; Q4 ~3 把下面的代码保存为一个bookmark_page.js文件" Z5 }6 U, b+ R$ T3 n7 R8 U
// bookmark_page.js, ver. 1.08 ]) P% Y' |9 F. X% b* i) j
// visit: www.pdfhacks.com/bookmark_page/: L3 c) I, g/ f. ?. E" n+ ^
// edit:cjs 2008-02-17
6 q: c7 T7 @* [- O0 N9 |* m$ u// 1 修改为中文标签
/ d \2 H' U8 J* a o R// 2 设置书签时可以自动获取当前的书名! U- U" q0 }% |: l# G' ^. e
// 3 自动获取当前所在的页码与总页数,方便查阅2 w2 i5 j& P \- r% E9 Q
// 4 实现更多功能可以参看Adobe Reader的SDK
3 s2 k$ }- J: I, [2 F \( a; o+ O `8 |! T
// use this delimiter for serializing our array
/ V4 ?9 U0 B. u* r& `1 gvar bp_delim= '%#%#';
# e0 P/ p4 c: ?$ w! p( t8 ~& r9 i3 `3 Ufunction SaveData( data ) ...{8 O7 [# L. K# C/ }$ p* E
// data is an array of arrays that needs
U! @$ E- B; Z // to be serialized and stored into a persistent
1 H! k7 S. e0 W( O // global string) o/ D o! l8 n5 X. j7 u& [
var ds= '';
; T2 Q& D" Z- j5 U, k/ ^! m% X for( ii= 0; ii< data.length; ++ii ) ...{
6 c) W4 h( l( ?; A$ E for( jj= 0; jj< 3; ++jj ) ...{# @- s% v( i, V0 R. F+ G
if( ii!= 0 || jj!= 0 )
) s2 `7 g) a S! B ds+= bp_delim;
$ R2 s! v/ K* E$ R- |% k5 `9 p ds+= data[ii][jj];; u$ E! D( M- P) Z( S z1 ?) k @
}2 U; p- q& j3 @6 l9 t0 V: x n
}& }4 X0 m: ~& `" l5 r5 m4 z
global.pdf_hacks_js_bookmarks= ds;
' e( z* p- l* d! B# f/ [' Z- Q global.setPersistent( "pdf_hacks_js_bookmarks", true );5 ^; |; g: z# {) E1 ]
}
- k9 l1 L& d' {# y5 O, ?) }function GetData() ...{
# V @' R& ~# O6 ^9 ]# l4 F- _ // reverse of SaveData; return an array of arrays
4 f& F( d4 ]: e/ L if( global.pdf_hacks_js_bookmarks== null ) ...{
- W7 t6 c$ f8 ?4 a. z) i return new Array(0);* Z3 p, [9 \, Z( x0 \: O/ W9 m
}. X2 P- L5 \! F! B! l) {+ `4 N- [
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
) U; h9 N2 W" `( Z% F, y var data= new Array();
) E7 A: }. `( T for( ii= 0; ii< flat.length; ) ...{" Q# `( T0 g) [1 g0 x2 n: o* Y
var record= new Array();5 K) Z1 {) ]. O' _# W
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
8 h6 _9 ~* ^& C" N) X record.push( flat[ii] );1 ~% o- H: e, p4 U8 _
}5 Y, n7 r& Z% R. b1 P! D0 B6 {7 d* n
if( record.length== 3 ) ...{
8 Y8 V2 i% y G" [2 R9 z data.push( record );7 O7 t! A+ b& R
}$ a/ s7 M) f" y y! W9 W
}
1 M: q8 C+ o; C/ L. M3 F/ ~ return data;3 L7 U7 D3 ~# A' B5 l! Z; b; z! V
}
4 F7 s5 ^+ G4 n& f0 Y* v//Get Current Date
; S- ^* W6 y- w# y4 Jfunction DateNow()...{2 R& h' `5 G: l
var d, s ;
4 N, t4 l1 p8 b" e8 J d = new Date();6 h2 X8 R$ Q! ~3 e: ~
s = d.getFullYear()+"/";' w/ R% {- ?6 V6 D c
s += (d.getMonth() + 1) + "/";
0 s; f- V8 h" J s += d.getDate() ;) R# `( y2 U9 V
/**//*
& x* v( k8 h# C/ n- u9 e s += d.getHours() + ":";
- ~$ k2 e3 p7 l# H8 P* u s += d.getMinutes() + ":";$ G; e: d: ]$ @: b
s += d.getSeconds() ;6 b" }7 z2 w" k7 A! B9 o, b
*/* @, Y" ]: ]) W7 E5 J( j8 M
return(s);" w+ e% m, F7 @( @
}2 I, D! s6 I9 c
$ e5 s, M1 F3 x4 q6 g8 {function AddBookmark() ...{
& ~( ]4 e" S9 ? // query the user for a name, and then combine it with
% i% a; N! M$ Y, \# B: g- h // the current PDF page to create a record; store this record
0 `8 g2 m! }) p0 W- B var thisfilename=this.documentFileName; [9 S6 J" r9 _$ P( K2 V$ G2 O
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
' h! E6 P, [* \9 ?2 D% m var numPlugInss=this.pageNum+1;
( ]1 b$ S5 `3 x6 ~ var currentdate=DateNow();1 P$ d" S( j% p+ f2 Y7 q
var label=
; A1 T8 {8 T3 L x, I9 r app.response( "书签名称,可以修改以便于记忆:",1 E4 @* i4 _- M/ A, Y+ o( J) ^6 J
"书签名称",
/ x2 j4 d- S- t5 q "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,1 | h7 B! q8 u
false );* ?- O+ ?, H0 i) S1 @
if( label!= null ) ...{
7 y! ~. ^& R+ |. j5 y" h, G var record= new Array(3);
+ R& k* L V8 n$ l$ R9 h6 H record[0]= label;
2 a: n: i- ^( i7 n4 A5 K r1 p record[1]= this.path;
) j2 ^: o' H! w3 r5 m6 W9 [9 M record[2]= this.pageNum;/ J5 S" P0 M1 B7 v( c9 q L5 |7 [% B
data= GetData();
. u7 Y; e: [6 j0 q data.push( record );
: d1 y3 j- H, `: V5 t SaveData( data );' B; v% \3 B9 @9 V7 L- e% G
}. n. D$ X) F/ g& E3 J( r
}
8 \6 x" s3 V5 a+ |5 q6 qfunction ShowBookmarks() ...{
. ~% }0 u- h; T+ U- t // show a pop-up menu; this seems to only work when
9 p$ A# J/ m, o1 `9 ~/ ^* i8 S* g // a PDF is alreay in the viewer;1 F3 |& Y6 y" \; b' I) a
var data= GetData();
/ X" Q- L9 Q2 t7 v1 t5 K! a1 Y var items= '';
0 W7 H3 U' D" s# K4 A% ^( B) B for( ii= 0; ii< data.length; ++ii ) ...{
. C' G1 o5 z8 L# ]8 o z& s2 k1 N if( ii!= 0 )
6 G1 Q) l) \0 F0 {0 W5 J1 f! [$ X items+= ', ';0 x* I. B" Z- J4 r% s
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
: \" l! N& F: n }% a7 t. R( i# l" d" r0 {
// assemble the command and the execute it with eval()
8 i8 f9 M$ g' F var command= 'app.popUpMenu( '+ items+ ' );';' w( ?+ g5 Q6 K- k" r; Q9 g$ w. J
var selection= eval( command );
: }' A9 v# k: [1 a if( selection== null ) ...{
9 L! y8 f) [; J+ w4 m$ L' Y4 F( | return; // exit( r T. I4 b! a# @/ J3 g
}
" N' |8 I5 P8 f* c' C // the user made a selection; parse out its index and use it8 v; g- E0 K7 e$ {! f6 O7 z; `1 V
// to access the bookmark record& Z( p& Q! F) l+ f
var index= 0;
2 W' K5 l! [1 [) l& K$ u // toString() converts the String object to a string literal
2 @& d6 ?3 F7 c* _4 s1 s // eval() converts the string literal to a number Q; l) t7 J- o! n, Z
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );9 W: h+ h& f! L5 W/ L
if( index< data.length ) ...{
' G, b2 V6 \/ ]5 c. O; n6 Y+ I( U try ...{9 G1 e, s `" N2 V) @* Q
// the document must be 'disclosed' for us to have any access9 q- v1 `9 x( X- e
// to its properties, so we use these FirstPage NextPage calls
% H5 {! o$ A0 H7 R0 P% b1 Z, Y //6 E9 o& q1 ]4 E% M
app.openDoc( data[index][1] );. V$ V" L9 F9 F" C, [" u$ m
app.execMenuItem( "FirstPage" );' G. Y: r; [+ N7 V& _
for( ii= 0; ii< data[index][2]; ++ii ) ...{
- L9 E8 w9 g' u app.execMenuItem( "NextPage" );1 L; d! K* v z0 z# p1 I
}% r: w s: X0 p9 F! \8 s) N6 P# D
}1 Q9 v+ ^* T$ O4 o: ]8 B* B
catch( ee ) ...{( j8 Y3 j; d) n7 _; j Q6 i6 B- z. k
var response= 4 d/ p T. i5 c, T' Z2 Z* P' v
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");: a) P) H2 H1 `+ p
if( response== 4 && index< data.length ) ...{
8 n, i4 ]! l& M, p data.splice( index, 1 );% q u2 m3 X, r. f5 R9 v- S
SaveData( data );
, N5 g, v" v8 b }& U; d" r( l( e: H0 s
}
5 R i Q" n a+ D }" j- p+ C$ \! a# w8 W
}
+ t0 w T2 [. W1 f' G. hfunction DropBookmark() ...{) e. g' L8 y* A8 ~7 w
// modelled after ShowBookmarks()" y7 N" I/ t m& L
var data= GetData();: ^* o/ k5 ?! x1 X- w; u
var items= '';! M2 y, l2 I! |
for( ii= 0; ii< data.length; ++ii ) ...{( z: G2 z) p4 w1 q( L8 V# D
if( ii!= 0 )" ^# ^, H0 H+ P8 W) p/ S; w
items+= ', ';# T( g m R0 q( B( i5 G
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';8 D1 V, z/ }0 e% h
}
/ d) K; Q [$ g; X var command= 'app.popUpMenu( '+ items+ ' );';
5 ~4 w/ P+ n0 o, C- f$ \- e" \ var selection= eval( command );
8 S7 ?6 A8 m; Y; J if( selection== null ) ...{
8 {0 K" r7 y" E9 I/ s0 ~ return; // exit& i3 ]/ o7 m; r& F8 C5 j% w# B2 H
}
' K0 f$ e& a1 j a4 y( O6 C$ A var index= 0;- G6 h7 ]4 t* @# _0 K* ]2 X
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );0 q H: Q1 M5 _$ W% D* E9 [4 T
if( index< data.length ) ...{
$ q3 s2 k7 e. ]3 T data.splice( index, 1 );# I0 z& {* s" Q8 Z' k1 b. E8 B8 {
SaveData( data );$ ]! @! {& R8 r& F+ |" U2 ]. o+ m
}; y% g9 {- b9 p) a# A0 O
}1 @' I5 l' D8 o) h. v
function ClearBookmarks() ...{
9 Q8 X7 `" W) f) A1 @ if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{) X0 F/ e" b1 ?
SaveData( new Array(0) );
/ r1 F/ d& l7 e* e8 T }- i& n; U1 _4 l: e
}0 R( _+ E1 C( |3 w% M- Y* c/ k
app.addMenuItem( ...{$ a. A! R7 m" N* V
cName: "-", // menu divider- j4 }( W* m& w+ J4 L5 I( A0 ?) s+ n. W
cParent: "View", // append to the View menu
O+ d; @3 U& [& e6 {cExec: "void(0);" } );5 N5 l j2 V0 l2 }) Z& m! J
app.addMenuItem( ...{
. ^- A U6 r: Y- N2 e* ycName: "设置本页为书签(&B)",
8 @ z8 b5 f. x0 r y/ Q/ C/ J) ecParent: "View",
' a k" E$ b7 R/ o$ C# TcExec: "AddBookmark();",
1 L3 ^) K6 ^5 v' FcEnable: "event.rc= (event.target != null);" } );
( w9 y3 h/ F8 H$ Y/ k9 Fapp.addMenuItem( ...{ y0 ]8 q$ J/ U. U+ c `
cName: "转到指定书签(&T)",2 M* K' K! H) I& M# A1 o
cParent: "View",: i. Z4 ^: Q4 H+ U2 {1 N
cExec: "ShowBookmarks();",7 }) R) I7 a2 m- s1 f( U1 c! I1 Z
cEnable: "event.rc= (event.target != null);" } );! H4 _% p% v7 S) B
//cEnable: "event.rc= true;" } );! Y' E4 R) q y
app.addMenuItem( ...{
$ X+ b6 K7 K+ K& x! L7 O0 m. U& JcName: "删除一个书签(&D)",
4 J4 h# N; |' |* TcParent: "View",
3 W# B5 |/ m- x5 k5 e/ g- |6 f7 [* [5 UcExec: "DropBookmark();",2 u8 T4 g4 }! }- H1 Y1 Q m$ o+ D. Z. ~
cEnable: "event.rc= (event.target != null);" } );
0 G! g3 |7 O4 `" g$ d# l; _app.addMenuItem( ...{
- p) d2 V. P: n4 CcName: "清除所有书签(&C)",
1 j% f2 ?- |4 l% N* G" ]; kcParent: "View",
( W7 x9 D3 W. M0 h: s' ?" |4 OcExec: "ClearBookmarks();",
+ M$ j! U; ]3 @( s5 D6 |4 McEnable: "event.rc= true;" } );7 u# v6 T8 @8 ~
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
; ]& q8 I* ]( Z# {5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
5 a% x5 A- t; J; t5 a; u: s1 v d6 j9 ?- |- ~. T1 R
+ |9 ]0 x, w4 j1 U6 P3 L# b- [% J5 f本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|