TA的每日心情 | 擦汗 8 小时前 |
---|
签到天数: 2402 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法! K! S. u. l6 E8 |
1、打开编辑的首选项项4 I" O/ l G* x: ]2 H
0 ]) {! Z. a. ?; O+ }0 i
2、确保下面的选项都被选中 b# P! L8 Z l6 K
, k% {8 N# c. v6 l- h7 n$ v7 n& K3 把下面的代码保存为一个bookmark_page.js文件- G/ X3 Z; g0 U2 [ ?9 A0 e7 U3 P
// bookmark_page.js, ver. 1.0
7 o& q& h0 h1 J: m. q// visit: www.pdfhacks.com/bookmark_page/
1 I7 i& m1 b2 r# Y; U6 Y. o$ j! o// edit:cjs 2008-02-17 3 e M) E/ ~; c: S5 C4 r: P
// 1 修改为中文标签; U7 e6 Q5 w7 K0 `8 ?
// 2 设置书签时可以自动获取当前的书名
. }3 @' J* C' ^8 P% }# ^0 i1 F// 3 自动获取当前所在的页码与总页数,方便查阅
2 |' m* w |( ?" C, _. d- X// 4 实现更多功能可以参看Adobe Reader的SDK
8 E0 b5 z. ]" X5 ]$ p8 Z1 d; }& k- F; g# } M" { L5 M$ j8 W
// use this delimiter for serializing our array
; {# X6 U$ w8 z& {+ gvar bp_delim= '%#%#';
: n Y1 @* q, P+ vfunction SaveData( data ) ...{8 |5 J w5 t( h! E! ]) q6 P! E
// data is an array of arrays that needs6 V7 [- M: W4 P% ^! ]. ?$ n
// to be serialized and stored into a persistent
$ u4 Z/ i8 _! f5 |# q7 H // global string
) ^! c, R0 d, R- v1 u7 S' } var ds= '';6 j/ A1 }) O% q& E
for( ii= 0; ii< data.length; ++ii ) ...{
/ K+ A% D& C* A \& Z7 O for( jj= 0; jj< 3; ++jj ) ...{$ n' a, B/ x" b# }9 o8 S& k) E
if( ii!= 0 || jj!= 0 )
! V" x6 `- S o ds+= bp_delim;7 u7 L5 W8 s; h1 U. c/ K9 C) n
ds+= data[ii][jj];
( `) X% p# ?6 H7 I }
1 U" o) g) y. |6 ^4 z }
8 v& F) c: M# A' w8 n2 U# a; C! w global.pdf_hacks_js_bookmarks= ds; f0 x( t- w: v; v4 ~( `* W
global.setPersistent( "pdf_hacks_js_bookmarks", true );
3 K: Q9 ]0 k1 W& y0 U( c}3 p+ M# w$ N' t
function GetData() ...{
" K/ }' c' N: l& o- e // reverse of SaveData; return an array of arrays
9 _6 v5 ^& [8 v/ |5 i- }% Q if( global.pdf_hacks_js_bookmarks== null ) ...{
2 o( u0 @3 R+ n; K( L; s return new Array(0);9 Z- x! B, ~0 x! a4 z
}3 f2 U$ [9 Z3 H) o- U% @
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
' N5 E$ y+ U/ \' W$ @ var data= new Array();. ?; q7 h" n/ i' c
for( ii= 0; ii< flat.length; ) ...{
9 z. Y0 s0 w @5 X1 Q var record= new Array();
9 O! A# O2 {9 i v for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
0 T- {+ L; r% s( A9 u$ ~) v0 x record.push( flat[ii] );
) ?$ a) J0 u6 d: C* g+ B }
; O% W6 W& K$ A4 A if( record.length== 3 ) ...{
! k4 ^' N1 B0 B data.push( record );
/ x- s3 C( A) \% Q! }. q2 u+ n }
' t5 E& r+ E4 P- K8 f4 v6 S1 r }
! b- F5 |% _# X! g" | return data;3 h" V5 h, d' h5 p0 C! g
}1 m5 o% H7 A6 w; ~7 m: B
//Get Current Date
, S. f* v0 t$ h. ^4 y/ Nfunction DateNow()...{
4 p8 @: z {* i) J, G' G var d, s ;5 R3 g* \9 X5 l0 L7 ~
d = new Date();
3 g R5 y( f# W4 ~0 G s = d.getFullYear()+"/";$ r: A/ c3 p3 Y" A) U' _' P
s += (d.getMonth() + 1) + "/";3 E* Z; e$ n* G: o% Z# w
s += d.getDate() ;
0 o: D, G( a) k+ a$ i' k$ E( S /**//* z0 z2 s; P$ `4 G- x& S
s += d.getHours() + ":";
i$ O: p$ e( a! \; d s += d.getMinutes() + ":";( @. h# l# k( U
s += d.getSeconds() ;
% a2 g1 a: Z( l) Q9 ?# M */
( K# ]8 |) p/ q- Q) q5 x8 t return(s);
0 R3 H/ ?2 r2 W; g}+ C) M& R+ {& ~) _
; v L6 W, E. Ufunction AddBookmark() ...{3 { j' z( ?. y" g4 Z
// query the user for a name, and then combine it with
2 ~$ K1 j3 i7 `: U // the current PDF page to create a record; store this record. P% L4 e8 L/ _; s! m4 |
var thisfilename=this.documentFileName;
6 P ?9 [+ k R thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));) D, F, v8 P1 u+ ~* [
var numPlugInss=this.pageNum+1;+ j5 f; z) F3 @9 g, i$ e" [
var currentdate=DateNow();
% {3 k% n' E2 d* `- M" n var label=
& b+ ] d! K' L! {9 i app.response( "书签名称,可以修改以便于记忆:",
- p$ V6 |' e' I; B1 C' v P( ?9 \ "书签名称",7 m+ H: `8 `2 g2 O, W7 _5 I. g
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,2 p, k8 ^/ B) k
false );
" ~! k4 }' N7 d' B0 s if( label!= null ) ...{
4 l& U% ~- G) [ var record= new Array(3);" S1 L' ~5 F# I s/ D6 U2 P
record[0]= label;& l# s. |# ?2 V1 j" ^9 `3 q
record[1]= this.path;# u% q, t- d4 h/ J4 R0 Z
record[2]= this.pageNum;
$ ^% G2 j" m. g/ h data= GetData();
- n" K; ]2 X6 ~0 \3 m) _8 I7 h data.push( record );9 h0 r+ b8 I, `- Z; j+ [/ m- Q
SaveData( data );
! S9 u0 q6 B& K9 V. C; \ }
! @- [ ^, C7 b; @! |+ G. x8 {}6 r2 {8 u. ?; w1 t
function ShowBookmarks() ...{1 U; K8 {$ \ t
// show a pop-up menu; this seems to only work when3 x7 a; P, e9 j, [/ m' B
// a PDF is alreay in the viewer;
% ~9 K6 M R- J0 o0 N var data= GetData();
2 @8 Y' c0 K4 e. P+ A var items= '';
4 p* I" a7 t4 b2 g. ]. q' u) ] for( ii= 0; ii< data.length; ++ii ) ...{0 |$ k. w! @0 x' y0 k) T, E) O
if( ii!= 0 )3 [1 X7 H, \+ u- S9 }
items+= ', ';1 j$ I/ D7 ]3 y. K0 s7 d% _
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
! E, U% c# _. }7 [; D }
. x6 v! h. H! R // assemble the command and the execute it with eval()+ |: ?+ n- ^1 F1 X
var command= 'app.popUpMenu( '+ items+ ' );';
) w6 l- F1 M7 u5 E* \ var selection= eval( command ); ?; j) k* a9 [5 C% n+ h
if( selection== null ) ...{
! b2 H, d5 @, h# M" j; z return; // exit
" t' G+ g0 O2 ? }2 }0 G" n% m" K' u7 D
// the user made a selection; parse out its index and use it2 }; J! f+ m9 H6 K* u1 E
// to access the bookmark record" o; h* P0 o# e8 m4 h' x
var index= 0;
3 g) P& n' ~, u _ // toString() converts the String object to a string literal* ?5 Q8 A! x0 J s! Y+ U* F
// eval() converts the string literal to a number
! o# h) G3 V$ G, f* Q index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );1 ?* w- |3 d4 q9 R
if( index< data.length ) ...{1 [: A9 Y6 e8 o1 V% J$ T$ O
try ...{
2 A7 u) X0 H* o" R7 J3 l x // the document must be 'disclosed' for us to have any access; \1 E- S( D! B1 ~- o h
// to its properties, so we use these FirstPage NextPage calls
2 T+ R# d8 l4 l) r //
0 B7 T9 X, x+ @9 J app.openDoc( data[index][1] );* P7 z9 n7 P9 r/ \8 F8 S; e
app.execMenuItem( "FirstPage" );
9 j: m' Y4 e. W for( ii= 0; ii< data[index][2]; ++ii ) ...{
B3 E/ m3 M7 ]% V" e app.execMenuItem( "NextPage" );
# J) } N4 _/ ` }8 Q5 T2 q4 @9 O
}
" R5 r4 @* n% P' {0 E8 v catch( ee ) ...{$ [' l/ [% h4 k7 L6 t$ B/ m9 X, R
var response= ; U( D% V* ~6 H$ Y" p$ }! y
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");# E- u7 W2 e7 X: j0 v$ J. {- n2 l
if( response== 4 && index< data.length ) ...{: o, \# F1 Q5 \: d' F
data.splice( index, 1 );: S" f) ^9 j8 r5 s T) v
SaveData( data );- ?, B8 w C( W& d% t% ~
}
( ]4 m6 W" y7 y. y0 C. l }
+ \. y# R+ i) z& i4 e9 [ }
( b, g! \% E, u}
9 U1 d) X2 H" \' C/ F. m! m7 efunction DropBookmark() ...{) d% P2 d- _( a
// modelled after ShowBookmarks()
$ j" F5 o2 u; ^* ] var data= GetData();
. `- R" C; k! }. z- u: L var items= '';
8 e" I# `; N, l" l6 y2 n for( ii= 0; ii< data.length; ++ii ) ...{1 a B! Q/ B" q; g, P
if( ii!= 0 )3 _5 K- O& m+ \- Y# o0 b
items+= ', ';
( d" _6 n" O( Z3 b items+= '"'+ ii+ ': '+ data[ii][0]+ '"';+ ~$ M9 z" p; }: z8 M$ f, _
}
. e7 w; S* U2 H6 r0 m& _ var command= 'app.popUpMenu( '+ items+ ' );';
- a- Q3 Z0 d, N3 e$ k var selection= eval( command );& G7 W6 F9 r5 a/ a7 l8 x) L. t2 I
if( selection== null ) ...{
, _, y; e. y l' Z4 ] return; // exit
2 @1 v3 s i1 K1 B0 Z- | }" b2 q- J% F- t6 j
var index= 0;: G& {$ j* v5 r* |1 J
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
+ Y5 |7 {+ l: t/ Y& v. \8 n S if( index< data.length ) ...{# x/ T) v3 u% h
data.splice( index, 1 );
3 _4 ~! U" h: H3 f7 s& T3 E SaveData( data );1 d/ X1 ?" N) W! n9 v! w3 V
}
; a; Z1 p) t4 t" p1 L* ]}
1 P& B4 d# O! m- O) ~+ ^# E$ Wfunction ClearBookmarks() ...{
/ e' L4 [& ^3 c, Q3 C if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{; g Y0 h9 T. V5 P" E
SaveData( new Array(0) );
" H/ F$ Z* h4 K+ D3 e/ o6 B }
5 S# Y& M" J) H2 n7 Y) c}
& |7 f" e8 J5 |app.addMenuItem( ...{0 j2 G4 ~ P, L7 |
cName: "-", // menu divider
% W8 D \' H4 jcParent: "View", // append to the View menu
?5 y0 ]) F# S: T( H5 j0 NcExec: "void(0);" } );- ]( Y. r0 t& I- T) D! z
app.addMenuItem( ...{& `9 h" S) a w0 v% k
cName: "设置本页为书签(&B)",
4 o$ }9 m+ j4 I( Y0 bcParent: "View",( W6 G3 x9 v) _! Z. }$ ]$ [
cExec: "AddBookmark();",( b# [+ o* ^" j
cEnable: "event.rc= (event.target != null);" } );
. F6 f+ j- n8 R0 ~ o' q" vapp.addMenuItem( ...{# v: v( R3 x5 p; X0 o
cName: "转到指定书签(&T)",
2 t" Y3 u) z+ U4 l7 A% ocParent: "View",
( V$ R- M2 C6 y9 qcExec: "ShowBookmarks();",0 }) m4 o) j9 [/ [- k" k. Y# X
cEnable: "event.rc= (event.target != null);" } );
5 N& o5 f! q u/ s1 R//cEnable: "event.rc= true;" } );
# F( I4 X! d/ z: O2 t7 ?2 _app.addMenuItem( ...{
( u, O P+ Y4 u4 tcName: "删除一个书签(&D)",5 i# A- W9 y/ `
cParent: "View",0 _8 X. G' B0 \, v& {! m6 Z+ ^
cExec: "DropBookmark();",
5 m' k N0 y5 k+ x$ q. }7 \! NcEnable: "event.rc= (event.target != null);" } );' I6 J( {, ]. C( K
app.addMenuItem( ...{# O* {0 Z: ?. Q5 _+ z$ A
cName: "清除所有书签(&C)",2 p5 m2 {6 n% v, N: h1 y4 _
cParent: "View",
8 i& J3 h" B0 |6 B. {) V1 _cExec: "ClearBookmarks();",
: Z; N% [) z' Y- q/ D5 l1 c zcEnable: "event.rc= true;" } );
: Z5 @+ ?# l; _/ |7 h4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
0 V* B$ x( V, A8 N1 t5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
+ g8 s- }+ T% d1 M1 a7 d9 E) v: a% ^ i6 o
2 B# z: J$ J, U! p
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|