TA的每日心情 | 奋斗 4 小时前 |
---|
签到天数: 2388 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
. A; W* D2 F3 K% V- k1、打开编辑的首选项项9 ]" P) `0 F0 s
P1 \& Z( Q1 R }9 o9 o4 R L2、确保下面的选项都被选中
, K* o$ O7 |: I' \: P; Z, H$ W/ W B6 ^+ i
3 把下面的代码保存为一个bookmark_page.js文件; _6 K$ B, A. V- H
// bookmark_page.js, ver. 1.0, ?1 u5 n, y! a e1 c
// visit: www.pdfhacks.com/bookmark_page/) N" t& p; U7 K( Y$ I8 \9 m( E
// edit:cjs 2008-02-17 2 r4 C# `& y2 K, j
// 1 修改为中文标签
; ?! P1 j: n& m' Y3 Q// 2 设置书签时可以自动获取当前的书名
# i- o. |6 {5 u! w! m( U% F// 3 自动获取当前所在的页码与总页数,方便查阅. Q" F. S7 f o1 E5 p" T
// 4 实现更多功能可以参看Adobe Reader的SDK+ p# x- x6 `0 A- z# T" F3 Z$ M
' D& w# o) i( v- }// use this delimiter for serializing our array+ R) |# j! j3 {1 t: L( I- W8 M
var bp_delim= '%#%#';
; R( g7 h/ k7 s9 S( N; Ufunction SaveData( data ) ...{+ @1 g; Y' T% A
// data is an array of arrays that needs) m. o0 I% T4 H& [9 v7 Y0 O r
// to be serialized and stored into a persistent
! R! b* B2 @+ L1 ] // global string
* X0 \- v+ S" m5 a, G; A) d var ds= '';
0 `- ~ l, F6 J! I- ^ for( ii= 0; ii< data.length; ++ii ) ...{
5 D1 R) H, b4 \. d/ X1 n for( jj= 0; jj< 3; ++jj ) ...{
' v0 c; n6 L/ F! Q8 n if( ii!= 0 || jj!= 0 )' }1 ^( L/ D! G. d
ds+= bp_delim;
7 m- w2 g8 Y5 g5 }; A1 K* {9 U# N ds+= data[ii][jj];
- x4 w5 t, p# G) e! |( q. i }
: }% y; |) W" q* \! i v }9 v# [4 Q& s3 K( q/ H
global.pdf_hacks_js_bookmarks= ds;" ]9 J" e+ P T6 z' p2 U/ J( K
global.setPersistent( "pdf_hacks_js_bookmarks", true );+ J; R& x* B+ M! p) l. W+ c
}9 w; L1 i; k) Z2 u6 p4 z
function GetData() ...{
( D8 q% q# `/ ~" t9 c G // reverse of SaveData; return an array of arrays5 d/ G% W7 p9 M7 `
if( global.pdf_hacks_js_bookmarks== null ) ...{
1 ?6 D" c G5 {8 W3 z! N return new Array(0);' g/ j$ L4 l% S6 A. }1 c4 K% |7 w
}
3 }: c8 D/ `7 p3 t7 N var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
8 s* S9 w1 Z5 T. I. X8 n: S var data= new Array();
& ^" a' _9 z; C# P) u# ~' { for( ii= 0; ii< flat.length; ) ...{( m4 C/ `# `$ H; b2 \
var record= new Array();3 w6 B2 k/ q g7 x$ d: ^, z
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
; U) @! `4 Y4 K record.push( flat[ii] );
! C: X$ I \- C; v% t5 i' c }0 c% ~& x+ F; x! Z+ ~' Z
if( record.length== 3 ) ...{
5 A- q7 s: ^4 I1 }: ` data.push( record );
% q4 |$ J0 t0 H4 ~# ?3 y* j- c6 c }/ |1 L* c; L2 O2 @5 {7 P
}8 |; t, D; _6 o0 c
return data;
, X& i R1 ?3 h8 n}! S, z4 `' d3 R' X, s+ C8 r9 E
//Get Current Date
7 m4 O- C' t) f! l* F6 ~function DateNow()...{3 _7 |/ F! s2 j4 b
var d, s ;3 i' K$ Z' p3 m7 i0 B; z" h
d = new Date();3 y* C* f6 Q. c' Z G
s = d.getFullYear()+"/";
# i+ F& s) m( i7 z$ V9 |+ o s += (d.getMonth() + 1) + "/";, A9 a1 A' e3 x! y
s += d.getDate() ;# E. U- O. F3 e3 l; {- D
/**//*5 X' M& N1 m' o6 E, F6 ^* A. Q
s += d.getHours() + ":";' f/ F. q" R. X7 S& C( ^/ `
s += d.getMinutes() + ":";
9 s) L9 \& U8 t1 l9 M s += d.getSeconds() ;
. o* q5 _! e/ Q% m8 V! r */
* Z6 ?. X& y4 W N return(s);$ Q: v! h% V( q# Y" V0 n
}
: S, O: I A4 y* d- J& x Z
. U3 x/ }( S9 W$ N1 D- [8 i) m" efunction AddBookmark() ...{
9 k$ S4 J. w% N1 _* L" s% u" @ // query the user for a name, and then combine it with
9 Y _' |0 s3 f+ }) q // the current PDF page to create a record; store this record
1 s. f6 q1 b/ U* x var thisfilename=this.documentFileName;
) ]; u- j) W/ F% k$ K thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));2 o) ^) f7 Z: l& t
var numPlugInss=this.pageNum+1;( |% D2 j- z; a' o) a" A
var currentdate=DateNow();& o0 [1 Q+ f; R0 I! y+ g6 R! l
var label=
3 `; n" A1 Y* w1 t/ i' q app.response( "书签名称,可以修改以便于记忆:",3 Q: R% e8 o/ Y! ?6 x6 ?# S
"书签名称",
& X, d+ `$ _# J% e# s+ Y8 i Z "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,' ~4 H! }% z" ^/ b: v* n. h
false );
3 w6 C$ B, Y# m6 ^3 l' D if( label!= null ) ...{9 b, ]( c1 B" S. k' C; u. Q: y4 `
var record= new Array(3);
" C, e. S5 @$ r3 G' k record[0]= label;
) {" r( K- N( E record[1]= this.path;7 ~9 K& A3 y4 r6 T8 b
record[2]= this.pageNum;$ a/ Q% L: W! g, f' l% A3 t
data= GetData();: a6 a! b4 \3 m" R1 @
data.push( record );
) O- q6 A5 h* A p- Z U% ? SaveData( data );3 r6 P# }6 {& M! q4 F. s
}1 j x' m! T4 d2 l
}8 X# F3 ]0 O3 p2 c* U
function ShowBookmarks() ...{- c9 W4 ~; c# K$ z
// show a pop-up menu; this seems to only work when
' k: a3 ^* Z* K // a PDF is alreay in the viewer;& y! J9 B0 z. N9 [: @
var data= GetData();+ N! F0 `5 R4 ^5 t; ?
var items= ''; v# t. J% J: c! X# ?" J3 |: Q
for( ii= 0; ii< data.length; ++ii ) ...{- l- b( d% {; D
if( ii!= 0 )
' h# H" C/ L& S; N* u3 c items+= ', ';
: Q* j% S# @6 s0 [& Y) x$ [- a items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
4 c) b& s- d8 @/ V }
3 T/ V- \6 I( G( a" t // assemble the command and the execute it with eval()
. S& u# T c' G, w$ I var command= 'app.popUpMenu( '+ items+ ' );';) Q; t& k( y9 S; z) `8 h
var selection= eval( command );
, ?. v* A& [/ U. v+ r8 E |2 V if( selection== null ) ...{
$ ]* O3 c& ^8 Y+ i0 e) f+ |. {0 J return; // exit4 P1 z9 Z- G2 s+ u+ T; V. i$ y
}
0 z# o7 r5 t3 |- a1 Z" s9 B) g // the user made a selection; parse out its index and use it0 {) V1 D& O; y, }
// to access the bookmark record
' H0 `& a& J& V/ F3 j2 E: _3 { var index= 0;0 F1 P/ ~( n. v& n5 } B0 D2 Z
// toString() converts the String object to a string literal
/ C# S' P6 C' {& _) s // eval() converts the string literal to a number" ~# j( }. S r8 |: `0 M0 _5 R. k
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
8 v( ?/ H$ P/ j: x% a# S if( index< data.length ) ...{- \4 Y# Z/ I# P" s. r) R# h' P6 M
try ...{2 S& r( _# X$ h8 b. j6 E' G
// the document must be 'disclosed' for us to have any access
/ x- I/ b+ v6 \3 f // to its properties, so we use these FirstPage NextPage calls
! Q# m; T5 N1 F1 ^4 e //0 h! s, K# p( T! R) z$ t
app.openDoc( data[index][1] );
3 z# z2 N. C1 X0 A- B* R2 `5 n( }( \ app.execMenuItem( "FirstPage" );
' _) `; s! X( d: k' o* a; y6 \ for( ii= 0; ii< data[index][2]; ++ii ) ...{& a$ w# {7 y+ g& @
app.execMenuItem( "NextPage" );3 F& p0 ~- l: x; X; C1 z
}
: B# |! i" |- q5 r0 y& h* E" d }
U6 T; h) y8 V8 c4 j catch( ee ) ...{5 f2 [1 A, W- |+ k+ O) S
var response=
! p$ U# C+ t" p# F1 }; q app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");! H R+ k( K7 Z/ R) A+ f
if( response== 4 && index< data.length ) ...{
6 g W; i9 K2 |& W: t7 _" j data.splice( index, 1 );: c4 o4 c3 w q( ]
SaveData( data );
4 [+ k5 u: B0 e J; Q, h& g, h" j }
1 z5 {- T4 h& b! C6 d0 v }/ m; h0 }5 [ q/ B7 j& |1 k
}4 E. Y, T; N- E" E/ @; S* p
}
1 X8 F( v: l( N) G2 [2 P3 nfunction DropBookmark() ...{3 a. s, R; s2 F# P; q: E1 O0 E
// modelled after ShowBookmarks()
3 T3 i3 f& }8 ?8 g var data= GetData(); t1 G% n3 J2 }% {( a6 o
var items= '';
& Y m- l5 @ E, ?0 c/ k for( ii= 0; ii< data.length; ++ii ) ...{
" q: g8 x0 L$ R' N+ A if( ii!= 0 ); F1 D) Q; P$ L" Z9 L
items+= ', ';& }+ B+ Q/ ?, a
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';' D% x: }! t$ w0 w9 c
}
' J# J. [8 \4 j% |1 s1 C' u4 f var command= 'app.popUpMenu( '+ items+ ' );';& S' n4 @4 } E" Y
var selection= eval( command );) j. J. b8 k* @) y
if( selection== null ) ...{
2 [9 X4 c4 S; p& [ return; // exit) A5 r5 L% V, B) S
}# h6 B: ^7 I: F/ e: F) R1 D
var index= 0;) e( G; ^) u& S/ ^
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );& I* \9 b9 _2 v% E- t; K. v' [6 s
if( index< data.length ) ...{0 w. @2 S" D) x, ~& _; e
data.splice( index, 1 );: W/ U$ T' k- X2 Z+ C/ L9 P4 I
SaveData( data );9 y+ s4 K4 j! N% D& f
}7 H6 I1 b( T- m
}+ N4 A4 D% U* J: x* O9 n/ T$ {& I
function ClearBookmarks() ...{' x5 u- F/ w4 A
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{9 R8 p' p4 y% ~. g9 D7 ?; i* J. E% E
SaveData( new Array(0) );
7 K2 {* D4 e0 u$ ?/ v( E }" m& P0 q* {" R" h
}9 S3 n6 v h+ T0 _
app.addMenuItem( ...{
# B! z( `4 a, I" c% UcName: "-", // menu divider' f* T4 R( r# A1 f
cParent: "View", // append to the View menu
. _3 r! V4 [, b6 vcExec: "void(0);" } );
* u+ b: l7 A, v/ l3 Xapp.addMenuItem( ...{
3 f: x/ J( n& N+ CcName: "设置本页为书签(&B)",
( W# O. s2 a1 {& m/ x( B# BcParent: "View",6 Q7 V# p: R# {0 j- b5 r0 i
cExec: "AddBookmark();",* l' `( v6 M7 ^; p) p& l4 {: {
cEnable: "event.rc= (event.target != null);" } );
( B1 {( W1 {( s! s, w3 Q3 T& e& _4 j ?app.addMenuItem( ...{
$ n) J+ [6 y0 z1 gcName: "转到指定书签(&T)",7 u8 t. R2 R: ^5 `& }* k
cParent: "View",
" `8 U# R$ w |+ x8 VcExec: "ShowBookmarks();"," b& X' v1 I' w
cEnable: "event.rc= (event.target != null);" } );
' r% L& ?1 J! X5 p% Y( e1 T//cEnable: "event.rc= true;" } );
( \* n/ L4 G+ u# q0 B1 l( n6 d2 Rapp.addMenuItem( ...{
/ d6 l) o( ~7 M: Y( o# X8 tcName: "删除一个书签(&D)",* S$ w8 b; G, Z v9 f
cParent: "View",
2 I( `- f9 t6 a5 S9 @1 R$ ycExec: "DropBookmark();",
1 p& w, f8 Z. c4 \2 Q; {" rcEnable: "event.rc= (event.target != null);" } );6 C$ G, i# R; C! ^
app.addMenuItem( ...{( X; h3 ?) Q1 `) M" [2 ~
cName: "清除所有书签(&C)",; {2 s |+ l) H6 W- U
cParent: "View",
1 n9 q2 H' f# ]4 J5 ^7 zcExec: "ClearBookmarks();",
0 ~6 T2 b! P/ C4 I- FcEnable: "event.rc= true;" } );1 b' M3 N; E% R1 x; {1 l8 @
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
~6 b% i! K' q8 A: [; i" ?0 l5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
% }/ E( u2 B/ h, U! R; Y7 X
# z3 v/ R4 o2 i1 W
. C& k6 C( s8 }3 w本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|