TA的每日心情 | 擦汗 3 小时前 |
---|
签到天数: 2392 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法3 x; _; c' w' f9 H# h; e* }
1、打开编辑的首选项项
4 v# G. T8 H* ?( U' w
+ e2 C& h" L4 M# _4 [' m2 J2、确保下面的选项都被选中4 z3 }) u- w5 ~. |* n
4 z- p& B; J( J0 ?3 把下面的代码保存为一个bookmark_page.js文件; L& n9 Y0 e" b+ g- o
// bookmark_page.js, ver. 1.0" e3 t+ n, q" g0 H( @
// visit: www.pdfhacks.com/bookmark_page/' A& ?" R& b7 q
// edit:cjs 2008-02-17
# t) e- J8 f" W# e5 X// 1 修改为中文标签5 i# R4 Q% g- Z/ a" [3 d: V
// 2 设置书签时可以自动获取当前的书名% W6 a$ i* d5 \% L; U, W/ h
// 3 自动获取当前所在的页码与总页数,方便查阅
0 ~& n) s) o6 ~! D; k5 {// 4 实现更多功能可以参看Adobe Reader的SDK2 I1 _9 S. z7 F! d% a
! w+ K' K2 D/ ]* f; ]$ \3 S& H// use this delimiter for serializing our array! W+ ?0 G/ L0 N: S
var bp_delim= '%#%#';
# y7 f1 A+ S# _3 U) i! X; N0 z$ U$ `function SaveData( data ) ...{5 D' U1 I) U+ k |! [
// data is an array of arrays that needs7 [2 D: y+ d8 F" o/ J
// to be serialized and stored into a persistent
* }9 o2 |; @' o( P7 Y$ l // global string
% u2 Y. M7 Q4 g2 a* M var ds= '';
) {) n, J0 m' q7 P for( ii= 0; ii< data.length; ++ii ) ...{
/ I% E' l* g. p: A4 ^" R3 }& j" }* U! ^+ u for( jj= 0; jj< 3; ++jj ) ...{* ?7 u9 P- ~& ^' t
if( ii!= 0 || jj!= 0 )
! ]1 D% a( n, C% k3 [3 R ds+= bp_delim;4 a* A, V# e0 Y, c
ds+= data[ii][jj];# y6 c x3 N2 ?+ Z; q6 y
}
1 J. i* j1 P0 |# F2 W& r }
! Z$ o1 D) |8 Q' e global.pdf_hacks_js_bookmarks= ds;
* T! w% s) l0 t* m4 c( Q) u global.setPersistent( "pdf_hacks_js_bookmarks", true );
# \2 {% K9 o0 {: n6 ~9 V" {9 v) _}
" ~) F, @2 f) b D( Cfunction GetData() ...{
, M9 c0 Q4 W1 W // reverse of SaveData; return an array of arrays
8 O7 q" x4 c9 ?& k if( global.pdf_hacks_js_bookmarks== null ) ...{$ [' C; l! B- s5 n
return new Array(0);
+ D* A, S, A4 [! I; k }
8 V& P& s! N4 F& n2 K9 u9 b var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
+ x" s& v5 z* M8 Q7 | var data= new Array();
$ n' V4 m, f. K5 M% |3 Z for( ii= 0; ii< flat.length; ) ...{4 ~! e$ K4 c2 z
var record= new Array();: b& h4 j: c+ l& t& G8 k, s8 C
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{; |: I8 e: h$ l
record.push( flat[ii] );
5 I# w' U/ E# _& N( ~ f }
" ^+ \" A/ h+ g" G$ O1 ~9 n! ] if( record.length== 3 ) ...{
; G; V; Y- z2 a3 ? data.push( record );
/ ^8 ]8 C' s/ | } P$ R, G& o3 I$ g2 u/ }3 u; q
}8 o0 S6 B. Q) B; o% H3 @/ M/ @- g6 r, b
return data;* G% C4 x* ^+ W3 ~
}
/ H: ~; u' M( D" M. w, L//Get Current Date
6 _/ v3 w$ R0 A5 n- Gfunction DateNow()...{. E; `. A+ O. \: [" q5 ^; U
var d, s ;/ ^7 O3 R& m1 I# d( T% D+ z* |
d = new Date();; a/ I) u/ I: L" u3 t3 }5 L
s = d.getFullYear()+"/";" I& r5 J0 v. j" E
s += (d.getMonth() + 1) + "/";6 l9 X6 ]$ y; |
s += d.getDate() ;, p# b$ b$ B8 f8 O, M6 \6 M
/**//*8 k# N4 Q N/ G9 b
s += d.getHours() + ":";
0 `6 k/ k3 j& r s += d.getMinutes() + ":";
8 ?2 a! i7 n/ [' }0 x/ e7 y s += d.getSeconds() ;7 j4 i: b( V6 n3 |) R- Y
*/+ K3 N: Z( l7 j" J9 M( k- t
return(s);
4 H8 D( N! ]% G}* Q: ], B, G; Q; x4 q8 P2 a
. ^1 u. l- }/ l7 [function AddBookmark() ...{: W( P! B% T( { [1 l
// query the user for a name, and then combine it with
# u9 f3 o& \' P* ~3 v. c" j // the current PDF page to create a record; store this record
$ C7 ^9 l# l1 L+ y1 Y8 }" v var thisfilename=this.documentFileName;3 V) v5 M+ F. k$ G9 W1 q% M9 d$ b
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
) [# `; B, [5 n6 W7 W: T3 W) x var numPlugInss=this.pageNum+1;% ]( \2 N- C- _) T
var currentdate=DateNow();! R* z! o9 E! f, E# E
var label=
1 |2 p; ]1 S, } app.response( "书签名称,可以修改以便于记忆:",1 f8 Z% ?. B' V6 h
"书签名称",
6 q% a3 a2 A% Y! r& y' X0 m "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
) ?/ m4 y8 g/ b/ Q/ I2 k false );
# V1 O9 b# `# ?! M$ H2 X' V: y) G4 A2 _ if( label!= null ) ...{5 n/ }7 u2 X; C L* ?( S8 ^1 F
var record= new Array(3);. K4 S( g8 [1 r1 F0 w: {
record[0]= label;
/ i0 U* J4 M* c/ m% r record[1]= this.path;
' P! _. g- |+ ]' t' b( d record[2]= this.pageNum;
8 U3 c/ V2 \+ B" {, h4 }3 P; a data= GetData();
2 G) x& M7 F% G1 g* ?4 w data.push( record );. Q8 V4 R1 y- J: Y% Z, g1 Y
SaveData( data );
9 F9 d, |1 O3 b7 t }
" w/ x3 r# E- _7 `: i* x}
% P( y2 f* ~) R' h4 D- Mfunction ShowBookmarks() ...{; Y' }3 d5 L: B @8 d2 ^
// show a pop-up menu; this seems to only work when" R& E3 _! f4 |; I, k- G4 V
// a PDF is alreay in the viewer;
, B" g8 d7 z7 J! S2 |! f* s var data= GetData();
7 Q# m8 W* r9 M$ Q2 C3 ] var items= '';' Q# H- T1 v- y* H( o7 u5 h
for( ii= 0; ii< data.length; ++ii ) ...{
$ @" c3 z3 y0 E4 V1 \ if( ii!= 0 )
9 {' q- ]1 p- u, w9 H* \: ^ items+= ', ';9 G6 x, r( S+ S2 b2 p5 l. c" V
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';# c$ L8 k4 m" a& l1 H `0 c
}
- ^# ~6 b$ p6 ]$ G3 m5 K! k // assemble the command and the execute it with eval()" ? J* m- h+ b( _
var command= 'app.popUpMenu( '+ items+ ' );';
; Y& r- Q* K. D8 w2 l1 m var selection= eval( command );4 K# x/ E3 u0 s1 w: z
if( selection== null ) ...{; Z0 n7 O0 u* S2 y1 P* M5 V- q' \9 T
return; // exit
( m- D6 E+ @& I- b/ R% h# f. E }4 j9 \4 N8 o% R4 x# C5 G" a
// the user made a selection; parse out its index and use it
/ s4 O2 V$ D) m$ ` // to access the bookmark record
1 {5 K: ~& z; F; h( I% i var index= 0;: z7 G" [% o+ U _
// toString() converts the String object to a string literal; h U" \$ r& Y# Q
// eval() converts the string literal to a number$ Q7 ] `- z _; U5 P
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
?; R3 a: @5 \( [. `+ v if( index< data.length ) ...{
# }% Z% x7 P8 U, x try ...{1 K* J6 n2 p7 n% p+ C5 E9 p1 R
// the document must be 'disclosed' for us to have any access% p$ w" g& g. n+ T) r& }( D+ u
// to its properties, so we use these FirstPage NextPage calls
# S2 H+ ^+ F1 [7 k& j //+ J/ i D8 v* S" o
app.openDoc( data[index][1] );! a' z3 X. Y5 N( Z$ O
app.execMenuItem( "FirstPage" );
- c n: I/ w/ p for( ii= 0; ii< data[index][2]; ++ii ) ...{
" {( K/ {# j/ R$ B. D app.execMenuItem( "NextPage" );2 H+ I' N, R0 q4 t
}. b' x- `2 H2 d7 I* G
}
6 _& y0 @ b% M( R$ k( B4 i0 F9 g catch( ee ) ...{
. N( Q* ~; \/ B: ~( M9 J var response=
1 l& {+ |# [* M- r app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");' x6 `& h5 @. U
if( response== 4 && index< data.length ) ...{
p+ s' } K2 }+ j9 f2 G data.splice( index, 1 );5 {' q: ~" z3 y) k# U+ n: R5 a
SaveData( data );
: z" f1 y& O1 S5 A. ^" ]2 } }, }; G+ ~9 ?5 Y4 b2 A6 ^& u
}0 h2 ?' G% ?: J. j
}
+ K D; n5 W# m6 [}
; M9 @. h; s3 Q# r' pfunction DropBookmark() ...{
/ }* l) j, h# `* Z% V( l, ^ // modelled after ShowBookmarks()' P/ x5 F! O, B
var data= GetData();3 ^' ^- t0 }# | C" c
var items= '';8 u! |6 q5 o( A8 {, m6 f/ c/ Q, |3 q& ]1 h
for( ii= 0; ii< data.length; ++ii ) ...{
3 s1 {% Q; D ]8 d% Q5 @( u if( ii!= 0 )
- g8 p: C$ l4 l items+= ', ';! R- h# G* R$ ~7 H
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
8 G' P/ p( a. k* w# i! w' J' A2 \) A }2 @0 \ M+ p% ^, ]) D% P& ~# j
var command= 'app.popUpMenu( '+ items+ ' );';1 E4 u& a6 c; n& U R& S
var selection= eval( command );' [" S' V2 \7 z1 R8 \5 Y" u2 G
if( selection== null ) ...{& E/ [& e' a3 B# q1 {+ c
return; // exit. D0 t4 K* L; f1 A y
}7 s4 V! I5 v+ M* r h3 @ Q# @
var index= 0;
a2 d- R' X" o- ^: V I8 D index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
0 M/ [& h* o* _ if( index< data.length ) ...{9 K* S/ w# J2 H: w
data.splice( index, 1 );( [. B* e( d0 f4 B) T- C
SaveData( data );& p: a: ~; {6 F) w0 L3 C3 \$ m
}' K7 l2 N! N) v* m4 r2 h2 v% d" U
}" |0 v# z' C6 A/ q
function ClearBookmarks() ...{
. x3 X6 w0 I C if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
! X: k+ ~3 p2 w; ?" O+ M3 u( e: L SaveData( new Array(0) );4 H6 Y4 k3 _, M; I. q+ `& T; R, D9 {
}8 Y. o+ s9 r6 z I6 b8 E' A2 R
}9 X- I# I8 j6 Y0 j0 H3 ~2 g
app.addMenuItem( ...{
) H7 F! R% s: Y" s& L q; ecName: "-", // menu divider
! A% {1 R5 S: Z& W' fcParent: "View", // append to the View menu
/ o3 o# p3 p: `- Y. z, |cExec: "void(0);" } );* a: i3 v @. X$ h3 p B$ s
app.addMenuItem( ...{
; y: {$ g) A) V# XcName: "设置本页为书签(&B)",
6 L* u! b+ I/ _, H3 {cParent: "View",. q4 f6 d q$ P' I, h3 h( Q# W
cExec: "AddBookmark();",7 H& z/ P7 y" ^0 V* u5 W5 \
cEnable: "event.rc= (event.target != null);" } );
5 o/ D$ U- a& s7 S# j! J* \app.addMenuItem( ...{' L# f" {1 w2 K
cName: "转到指定书签(&T)",- z* e8 G. \$ z& v$ q
cParent: "View",
* p5 E( K% s$ ?cExec: "ShowBookmarks();",' s* G y$ G& l7 }5 }$ [5 T
cEnable: "event.rc= (event.target != null);" } );
/ g4 v% V5 D' c/ A# r% Y# n//cEnable: "event.rc= true;" } );
" w0 e: m& ?4 ^app.addMenuItem( ...{
% P2 Y7 e- z. W2 t2 |' NcName: "删除一个书签(&D)",( v# f& `& |# A; F
cParent: "View",( Z* a& o& ]5 ~ x( `
cExec: "DropBookmark();",/ O) q; R2 ~; o$ D
cEnable: "event.rc= (event.target != null);" } );
. {- N# s1 d$ N, Tapp.addMenuItem( ...{
) V3 r8 N& M: A, [0 \! J% O5 JcName: "清除所有书签(&C)",% A& K' t. k0 X4 R, ?
cParent: "View",
! Q; C! U% S K( M# dcExec: "ClearBookmarks();",
( S: T I4 |% K* @* KcEnable: "event.rc= true;" } );
$ D- y, H( N. Y# n4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下6 ^/ c8 S7 [" b& A: k: X8 q
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
) T& X* q0 ?# U9 I; k- `7 H
! i) [+ {" R* W( ^
" ?( u. e e c( D本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|