TA的每日心情 | 擦汗 5 天前 |
---|
签到天数: 2402 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法! M/ I/ u: g8 h2 e- f$ [
1、打开编辑的首选项项$ o% A7 U7 Q- n
1 a: K+ a/ W5 m/ P' T5 Q2 r
2、确保下面的选项都被选中
3 V( w) ^- W7 `& L9 A
7 F8 p7 z; n L' w% y+ B5 h3 把下面的代码保存为一个bookmark_page.js文件: z8 U+ b$ m! v; g
// bookmark_page.js, ver. 1.02 L% y) J: x# {
// visit: www.pdfhacks.com/bookmark_page/
+ i" Z* o3 d3 k' L9 k// edit:cjs 2008-02-17 ( K. b1 w4 Z/ o" P& {
// 1 修改为中文标签
. F! |* g+ V( ?6 f8 O// 2 设置书签时可以自动获取当前的书名
6 e, W T! m0 F- s2 p// 3 自动获取当前所在的页码与总页数,方便查阅
/ |; q9 {8 \3 Y& w// 4 实现更多功能可以参看Adobe Reader的SDK
8 _! m) ]1 o0 d5 U6 D. H Q
+ U) M2 W5 L, V; O4 M5 h/ m0 v, J" c1 I// use this delimiter for serializing our array
, y6 M' @; s p" Zvar bp_delim= '%#%#';
# q7 }3 P) M, J# Ufunction SaveData( data ) ...{9 ]4 E) `) I6 _5 i0 h B5 H8 Y+ r
// data is an array of arrays that needs
6 W3 H2 [6 A2 S: v // to be serialized and stored into a persistent+ e! L H$ u7 D9 D% w
// global string
4 Q6 g. I- t2 K0 m0 s( J# f7 O8 O var ds= '';
# ^# {' P) t$ V+ f for( ii= 0; ii< data.length; ++ii ) ...{
9 e9 @! g/ V/ Z3 Z9 V. X' H for( jj= 0; jj< 3; ++jj ) ...{. f. t# w9 s0 t& Z& K" S
if( ii!= 0 || jj!= 0 )( Y+ N" V' _, [0 d8 A3 K/ x, a
ds+= bp_delim;) {6 S1 n: G3 J! Z, S) c
ds+= data[ii][jj];
) ]) `+ b |8 ~, f! V6 w }
) L+ U0 r0 c- t7 C4 d$ W }) E d3 Z' S- X. _
global.pdf_hacks_js_bookmarks= ds;
[" Q# j! N1 H1 Y global.setPersistent( "pdf_hacks_js_bookmarks", true );& B. B; n' f% Q+ U8 L
}! x. {- M1 R$ D% x( S b5 [4 J
function GetData() ...{3 g- }* Z! L* s3 k1 B# A; `2 `
// reverse of SaveData; return an array of arrays
" K4 d1 g: O! o- s) v$ [+ a if( global.pdf_hacks_js_bookmarks== null ) ...{
2 `8 t/ J8 `, R1 {( U return new Array(0);
5 [0 {+ X3 @/ C9 A3 T }
, b I4 O w7 A$ X8 c% j: }; l var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
+ R' N- i3 e( z3 {. z var data= new Array();& y$ u. ]! a' C9 \$ {
for( ii= 0; ii< flat.length; ) ...{# \0 t4 ~7 c! c: r" S* M9 d
var record= new Array();7 _' R% D5 D" R
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{) U1 ]. F4 J1 n( R) Q1 Q8 U( j# a \
record.push( flat[ii] );
0 d9 h( n! A6 G5 f+ H- T1 J }
1 M) y" O- }) b- r# j if( record.length== 3 ) ...{
6 R. ]& |% ^; ^ data.push( record );
% a @! x$ _# O/ y }; C2 x. l1 D0 a- a+ c: \% W
}, s$ [8 f; P# Q
return data;4 z) [* A+ `1 A0 K' `9 f; H
}; d9 e0 S* L% b" d
//Get Current Date! n5 r& c; P: W3 R7 W# ^# S$ L
function DateNow()...{
' `- @& i9 @( |6 t# t var d, s ;
7 n% X1 o; N* [$ c' m9 S7 m9 E d = new Date();
* C0 M/ @& _ I z s = d.getFullYear()+"/";
. P' \0 ~. T- Z p' ] s += (d.getMonth() + 1) + "/";1 u! q1 @- F4 P1 Y
s += d.getDate() ;
& {# s/ k5 U( t, @' J! i" o /**//*
9 Y. c) r: I& i/ T s += d.getHours() + ":";
% {( g7 l' P9 S s += d.getMinutes() + ":";
+ l, z2 p. I0 g s += d.getSeconds() ;
) B, w6 s5 h. ]' T */
1 ~; \5 k5 C8 }+ q' l1 N8 G7 [ return(s);
' n3 [& }, D. D' m}) V, t% Y* w7 w' T9 v% F
# s. w) E* V$ z' o+ L6 t
function AddBookmark() ...{1 P, m9 p F$ W9 W8 v
// query the user for a name, and then combine it with
% {; S8 P( S0 M* r! M b // the current PDF page to create a record; store this record
' M2 n" P Z- g- P9 i9 f1 W+ V, A var thisfilename=this.documentFileName;/ N' t1 d+ n7 J7 F
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));* [" M: I# A# X0 T* L' ]
var numPlugInss=this.pageNum+1;
: J! A n. V. f7 k var currentdate=DateNow();
7 D3 O7 o) z! N) F/ y. f2 Y var label= 6 v3 j" M9 B2 L1 b
app.response( "书签名称,可以修改以便于记忆:",: U$ i) f0 v9 w2 {% g5 _
"书签名称",) A1 O$ ~% X( E5 t( U% \1 J+ g+ T
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
3 N+ L$ T1 g* ?3 |9 G& x/ |% v false );- @6 M. ~! t, Z: T8 Q$ n
if( label!= null ) ...{
7 S+ _9 `8 ?. ]) o8 @' O n; E" k var record= new Array(3);2 N6 B X4 S: O, `; A5 R, r3 D
record[0]= label;( d3 r5 D" X' A8 X
record[1]= this.path;
2 ~: M" C" R$ C4 n+ W2 I5 a% p5 I record[2]= this.pageNum;9 Z4 M4 n- t: x4 {
data= GetData();. p7 h. n4 a8 K5 L. v
data.push( record );
3 _5 I W& c0 F t) ?0 g$ d& a SaveData( data );
/ r1 v" _ Q0 ]8 n5 i' l }, o/ o7 I* j6 {5 v
}
. E; |3 G. @& j6 yfunction ShowBookmarks() ...{2 N2 @/ [4 w# W7 }/ K0 r
// show a pop-up menu; this seems to only work when
: i: G8 G$ z! H7 v9 s8 i9 K // a PDF is alreay in the viewer;7 B3 V% o* Y* t8 X% U8 Q
var data= GetData();
N. N$ h# o( N' ?: I5 `2 g var items= '';' j" ~; f& U* f- F7 P& s
for( ii= 0; ii< data.length; ++ii ) ...{4 u/ J4 Z' I5 F0 J! n
if( ii!= 0 )
4 t! c- `% T i7 `$ Z" N) X items+= ', ';
" X+ r1 x! F0 @% D, J) \5 h$ N items+= '"'+ ii+ ': '+ data[ii][0]+ '"';6 X# Q( T- v1 a# Z8 e" K1 Y. n% _% Z
}
' {. G' n, S2 R# I# l4 w" f // assemble the command and the execute it with eval() S. d8 H' t; e* Q$ g# E
var command= 'app.popUpMenu( '+ items+ ' );';
, e8 ~; z7 q' {8 y4 k var selection= eval( command ); g# G1 S7 L! W1 [0 p$ @3 b
if( selection== null ) ...{- L7 {5 e/ E& Y5 S% B( G
return; // exit' m8 K% f$ a! m" [& H
}
& Z# ^% U; o/ z: I6 G% L- F // the user made a selection; parse out its index and use it
~* N) K- a! f3 Q // to access the bookmark record3 T- z8 }, g( y- ]( }9 x: w
var index= 0;
; h6 F5 _5 b- s# E y // toString() converts the String object to a string literal& z- H6 N6 u) I1 G
// eval() converts the string literal to a number: \6 o% E' G( e- F5 c
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
% a9 w2 L: {0 F9 E if( index< data.length ) ...{9 S" {5 C; l8 B0 U
try ...{# d% ~. S! B( N" x
// the document must be 'disclosed' for us to have any access; }' K, a7 o/ h# k- y" Z7 c8 a# H5 X
// to its properties, so we use these FirstPage NextPage calls
: Q% G B' j1 x- K- n$ ]8 C //1 ? P# w* D) {9 b, q* \% x" t7 e
app.openDoc( data[index][1] );
+ v2 T' d; Z$ A \( l, g app.execMenuItem( "FirstPage" );$ G% z! g Y) _$ I {8 O0 ?+ n2 y
for( ii= 0; ii< data[index][2]; ++ii ) ...{/ I/ K( @% J* ^6 U1 K5 F! J r
app.execMenuItem( "NextPage" );$ n0 k& X% }; o2 p( B' h
}
+ \% E; W9 P. u' P( m }
6 o9 k! K/ Q# Y( V' O catch( ee ) ...{
" C& ^1 c5 g0 c* j var response=
5 E9 r% b }" v4 X4 w) b0 X# O% u& G app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");& \5 J5 t; l1 j: h
if( response== 4 && index< data.length ) ...{) l$ Q- F7 j. ?$ m& ?
data.splice( index, 1 );
2 n8 S2 x; d9 d/ j6 G, B3 V; r SaveData( data );
) V% H+ C* G" X" D# ^ }
; p) H! N" z6 \ l+ W }" D4 N0 d% \ |. N) G3 \. Q/ c
}1 L7 q; [& q* x0 S# z9 D" t; a- N
}
7 \7 ?! b% s+ O1 pfunction DropBookmark() ...{
* I% H) D+ o1 j8 l7 X) p7 ]' L // modelled after ShowBookmarks()
; g" M7 l# ^7 ~# D, x. [2 F9 z& f, A var data= GetData();# ~# g3 S) \. s% b
var items= ''; I# B8 O* [, d7 Z
for( ii= 0; ii< data.length; ++ii ) ...{
! M' Y- w3 O [5 u( r8 d( h0 V% s if( ii!= 0 )1 J/ v8 g$ y5 z0 p H5 D6 T9 v k
items+= ', ';
$ r r. t- d- [ items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
( w: V! A' i- ~ }' f Y. u) O* C! {% q( \3 [
var command= 'app.popUpMenu( '+ items+ ' );';9 u' g1 b ~. H
var selection= eval( command );, S6 M/ e" ~! I3 x' v$ k
if( selection== null ) ...{: c1 f* N' a( l- G
return; // exit1 M& e+ q) P# V) A7 T
}7 b, {0 U4 z! ^. \% o% b$ @
var index= 0;3 @8 N5 u2 h0 B% v" d2 V
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
9 s8 ?. U* G6 {" {* v if( index< data.length ) ...{
( Z3 ~6 Q$ C4 `6 I* A g5 N data.splice( index, 1 );
o) u. k f! Y$ V4 a- e SaveData( data );
& P9 k7 {6 b+ P1 x; ~4 a5 f- i }6 Q1 X( m3 u0 `6 m; v
}
9 w( H+ n- w2 X5 S! gfunction ClearBookmarks() ...{
0 f$ ^4 l/ y& t3 l0 s- Q if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{# x' g1 ~, a+ }: y7 Z2 t
SaveData( new Array(0) );( D/ k1 D7 {9 s/ \9 V3 E- v2 c- q
}
5 ^1 j) _( Q" m}* p/ {- b" k/ l, n" }2 @" x
app.addMenuItem( ...{
I' \+ d5 L6 [' W, g* S1 j1 GcName: "-", // menu divider
5 _) {2 I; e2 W2 c! ccParent: "View", // append to the View menu
+ K5 p/ E B! l. z0 ] \cExec: "void(0);" } );- a: n7 v$ R5 o
app.addMenuItem( ...{
2 A+ m3 p/ Z) K6 P1 B! R9 ScName: "设置本页为书签(&B)",
M' T$ P& L! I: ?( h4 VcParent: "View",
- S( r( O5 X( ]; J" {8 ?! Z- IcExec: "AddBookmark();",
2 {. }0 E7 I; n, \, ~cEnable: "event.rc= (event.target != null);" } );8 m+ g3 R- e3 V3 ]0 z* M
app.addMenuItem( ...{6 W# Z; t' a. G. U' U; I
cName: "转到指定书签(&T)",
) R) V! |8 `4 V( W9 y$ R7 kcParent: "View",
) v- r) P( z0 A! v* _1 wcExec: "ShowBookmarks();",
K7 j1 N- c6 _cEnable: "event.rc= (event.target != null);" } );/ Y8 b9 @- K( B/ |: n( v7 U
//cEnable: "event.rc= true;" } );
$ B& {+ ?% T! ]8 ?app.addMenuItem( ...{5 p) ]; }) o( @9 x- n( r
cName: "删除一个书签(&D)",, u4 R9 o) [1 J: E p: Y
cParent: "View",! ~) \ X& e0 D% T. {0 k
cExec: "DropBookmark();",
; F/ S: k8 E/ ^. g, s4 q4 vcEnable: "event.rc= (event.target != null);" } );3 @( a3 D3 [( G" [6 y
app.addMenuItem( ...{
, L, ~) r6 ?* | b7 q9 vcName: "清除所有书签(&C)",' }3 @$ m6 R/ s6 i
cParent: "View",! y. I. ?6 \) l4 N( X, u
cExec: "ClearBookmarks();",8 v$ }, c/ G8 o2 S m( }; s
cEnable: "event.rc= true;" } );! R2 t o9 ^+ r
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下. D1 d- `- n+ ~4 j0 G
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了" i3 S. h0 e2 q
- [' _( T0 v3 s! h, e1 q
9 X+ R( T" _! b
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|