TA的每日心情 | 奋斗 前天 10:07 |
---|
签到天数: 2385 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法0 @4 y. ?( c& W) w6 C2 B2 X* ?9 {
1、打开编辑的首选项项
4 M: U7 E J: N) c0 n3 w* N( D8 g) }6 j
2、确保下面的选项都被选中
, }! p" Z/ v( S4 z: ]# j/ b
6 s& }9 y9 j/ g3 ~3 m3 把下面的代码保存为一个bookmark_page.js文件/ B- I+ J' L. J" @* u
// bookmark_page.js, ver. 1.0$ S' ~: O, i% b9 v0 \4 y
// visit: www.pdfhacks.com/bookmark_page/# T, `; K) E, \3 \6 B" C& h# g
// edit:cjs 2008-02-17
$ `! |0 b5 u3 \// 1 修改为中文标签
" m7 O; e) ]: V& t# q// 2 设置书签时可以自动获取当前的书名
- a7 Q# P/ d3 [1 w* v// 3 自动获取当前所在的页码与总页数,方便查阅
" g2 H0 L0 P! m6 r3 w* c// 4 实现更多功能可以参看Adobe Reader的SDK
. M7 O! X4 _7 V4 @9 b7 L+ o- y3 G
// use this delimiter for serializing our array: ?7 z. W8 z7 C. x
var bp_delim= '%#%#';
; y/ q- B% I- |: V( H/ t; wfunction SaveData( data ) ...{" B0 Z# [6 ~8 h K: o- @# q: g
// data is an array of arrays that needs: v8 ]9 b2 u6 Y+ s
// to be serialized and stored into a persistent1 a. Q4 P1 d8 g. h, k; L
// global string" z( B- C- E9 y2 z
var ds= '';
5 y. z) d4 k+ |1 P0 S/ } for( ii= 0; ii< data.length; ++ii ) ...{
7 B. ~5 V! S9 V* s+ L' Z5 r for( jj= 0; jj< 3; ++jj ) ...{, y4 D, J4 \' i& V5 N& n. ^
if( ii!= 0 || jj!= 0 )
2 X7 r/ u; ?7 Y' F, E ds+= bp_delim;
2 h( x+ S& h$ n' y5 s ds+= data[ii][jj];! U1 V7 q, k4 g7 E' D/ m
}
4 ]- n( r" p. k' I* h+ W1 M& j | }
2 ^6 W# J, j% f3 d! F- Q2 Q global.pdf_hacks_js_bookmarks= ds;& @, O/ o0 z- X9 {6 [
global.setPersistent( "pdf_hacks_js_bookmarks", true );" W! Y) {0 A+ m0 ~+ I1 B
}
8 Z8 @1 I" [7 }; v e! g( v) Xfunction GetData() ...{
, M2 _+ X& k. Y+ }, U. c // reverse of SaveData; return an array of arrays) R h" J8 _+ l
if( global.pdf_hacks_js_bookmarks== null ) ...{# F( I; l. O" O
return new Array(0);) g9 O7 V; j7 R5 O5 U" {
}: z/ ?7 G' z6 y! K% \/ F
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
$ I9 T2 I) [! J var data= new Array();9 V8 u8 H4 X/ k5 m1 ?- p5 @9 T) b _
for( ii= 0; ii< flat.length; ) ...{
3 e6 X3 |: }5 W+ h. O1 _ var record= new Array();* q8 T% t+ Q. _. x
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{ |4 C4 r, {# s, n/ l
record.push( flat[ii] );
* e. c# J. A7 W! {$ v }5 F& X( v! q6 n$ F8 W
if( record.length== 3 ) ...{
A# N( _0 q' ^! s$ G; V1 X! ?9 x data.push( record );
4 Z4 X. w) k. K: G; G1 T }8 N$ S# s* y* o0 v
}
+ m" C9 u! |# {3 I/ b4 t return data;
2 s1 { O4 a2 Q) g5 G}" g. W0 b, h& f1 d/ x
//Get Current Date6 f% t- h9 f' Y* T
function DateNow()...{
. f- W2 _+ t9 A4 |! Z var d, s ;4 Q2 J: K$ U |6 d
d = new Date();- U2 t* R, W8 B( F/ m! ?! c5 R
s = d.getFullYear()+"/";
! N# g! @* M4 I! ] s += (d.getMonth() + 1) + "/";# N m+ E. d% s. B2 c/ U4 p6 d% g+ u
s += d.getDate() ;
. h* F4 E" H! a: K1 r6 Z /**//*9 a- B+ s: Z- Z
s += d.getHours() + ":";
9 \/ t$ d) S9 L+ ~ s += d.getMinutes() + ":";9 c! o9 N9 F8 D7 [; ]* I
s += d.getSeconds() ;" H9 k, L/ J+ E# V1 ^- _& h ]
*/1 R7 ]3 F4 O' k u i
return(s);; F. z' v& {( C( P; |6 d
}
" B" m( ? A9 \" r# p: \8 o5 ?& h) z( t) E& B
function AddBookmark() ...{# c3 j: L9 J' _1 _" f4 ?, f
// query the user for a name, and then combine it with
5 k" k- r, P( g( x7 f& T$ Y: W // the current PDF page to create a record; store this record
; G2 L9 N) N+ L, R: ~; A( Z/ |' q6 O var thisfilename=this.documentFileName;; z* H+ ?: M# m: y: ^2 V
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));! _2 D" }1 `7 \
var numPlugInss=this.pageNum+1;$ B' N7 _$ @' k( ~4 J
var currentdate=DateNow();
1 f% F- [' A# x1 B* S" G var label=
R! K+ V2 `) Y1 p1 G: j( ^ app.response( "书签名称,可以修改以便于记忆:",
4 ~; l5 E& u. A$ B# G& |. J "书签名称",
+ R* F% f5 H. f "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
7 S5 x. e! |, m( ? false );
" g2 o' T) s Y, B$ `0 x4 M2 W1 j if( label!= null ) ...{
( o D. v/ ` O- I var record= new Array(3);2 f- ^! r1 \# i4 r# k, [
record[0]= label;* k( w' Q, R$ Y4 A& L( @" l' N
record[1]= this.path;: ? g6 D8 R1 [, s
record[2]= this.pageNum;
7 {) Q7 b5 x- W6 E9 ?7 u S data= GetData();: N/ J8 S' x# O$ s
data.push( record );
9 }0 d3 {- x/ }5 R# N( w1 ^3 n SaveData( data );
R1 B4 |$ ]$ s }
$ k$ q E" n" |$ c+ Q) s& x& `}% @3 J' ]8 ^* @7 q4 f4 ?' J
function ShowBookmarks() ...{
! R& S5 O7 k8 `+ z5 Q+ z1 t. ~ // show a pop-up menu; this seems to only work when) h: K% i# O6 ?
// a PDF is alreay in the viewer;: w N* k. B8 e! U: G& V' f0 h
var data= GetData();, \1 x2 ^. O& K3 _
var items= '';
: v* R6 x4 T$ p: ] for( ii= 0; ii< data.length; ++ii ) ...{
, A3 K: o. H' m& ^! \; Y' W if( ii!= 0 )
5 C3 c3 S$ }+ F% F; [" ^ items+= ', ';
+ n+ y2 C0 Q2 S, B8 q, F items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
9 a; D! i( P) w* p4 U3 q! o }" z* z9 p5 h+ J# V
// assemble the command and the execute it with eval()7 b$ K3 N$ ^) _) g0 U+ x
var command= 'app.popUpMenu( '+ items+ ' );';
8 s1 v1 U4 p% l% `& g- D var selection= eval( command );$ P. A7 g* l. z' w+ Q( z% c, P4 ~6 E
if( selection== null ) ...{) S3 V# Z) t; k+ [
return; // exit9 S, t* V% R- N B+ }" z6 [
}
% O- e. {! f7 i! I* @5 Z // the user made a selection; parse out its index and use it
3 B5 _; S, R, ? ]5 x // to access the bookmark record J/ [$ M: ~* v, M$ X# i8 _0 F
var index= 0;
m _9 j |2 c" X# d5 ]" \ // toString() converts the String object to a string literal
6 ^$ w# A5 e8 z9 F7 C // eval() converts the string literal to a number* ^" U! @; e" ~, O
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
( ?- f" r1 u+ `6 O; e if( index< data.length ) ...{ L: | K! k5 g
try ...{
9 K. J# ^+ b5 S' c6 t, X // the document must be 'disclosed' for us to have any access9 A+ D" k8 E- x! t
// to its properties, so we use these FirstPage NextPage calls
* z7 _) z3 W0 P, }- G //% n' R$ Y& [, L6 c0 d1 q5 Y
app.openDoc( data[index][1] );
% e" H) i# [- T/ ] app.execMenuItem( "FirstPage" );
) p$ h* B/ o' o% ]9 e; a for( ii= 0; ii< data[index][2]; ++ii ) ...{
1 H( D! {2 O& M' ` app.execMenuItem( "NextPage" );; p8 E0 t/ J! x( r& X& {
}( X$ [; b. u; c
}+ s9 `1 P- l- V
catch( ee ) ...{- _: U5 }0 @* k$ a6 y
var response= 4 { B5 p# V+ J7 R) I1 T' h
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");
- x; M) a( w0 z* L if( response== 4 && index< data.length ) ...{8 D( p4 E1 u1 f0 G
data.splice( index, 1 );
' C- Y1 q; N' a v2 C4 j' D9 t SaveData( data );/ @% f8 Z2 d% X& ?/ q
}
# v' ~" D+ U5 b/ ^& d& E1 \: @2 q }
5 Q# V2 W v+ ]% M" q }$ E" Y. |! b. P. M$ i# S6 d+ z
}
% V, c: |3 h1 Xfunction DropBookmark() ...{" `6 W: W5 ^& M! n0 Y* j o' Y
// modelled after ShowBookmarks()
v/ n; y0 d( b7 c7 ? var data= GetData();! ~' y F5 x! W8 j
var items= '';# w$ Q) d7 |7 m3 p
for( ii= 0; ii< data.length; ++ii ) ...{
5 X) u5 {- c X* z if( ii!= 0 )
2 t9 ?6 w# q: w. } items+= ', ';
. ~3 t# R) m& F! q3 n items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
" }3 ^* e; b3 ]8 T }
- o" u" K, t6 z6 j% P( j) c2 p var command= 'app.popUpMenu( '+ items+ ' );';
, ` d9 c; s8 ` var selection= eval( command );1 D+ t _1 u2 X8 Q8 P$ v$ H# B k
if( selection== null ) ...{
) u+ h% `0 e2 m/ U% v return; // exit# B) D# ~1 ]3 @' x+ B
}& P) T, }, a, Y( c
var index= 0;
5 Y2 D [% H2 B+ I) S index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
9 l: l" L7 {7 v9 k q3 ~ if( index< data.length ) ...{# G: V1 g& V& k$ v* L) o+ g3 ^3 }
data.splice( index, 1 );
- [# h- v" v- w) x1 F6 d# v SaveData( data );! U" T2 @% ~8 R3 W6 S% F9 B
}
# ?- J5 b5 z- g}
8 m% i3 R0 Y$ _+ V$ R- B0 P8 c1 Rfunction ClearBookmarks() ...{
. V3 a9 r9 f% E+ y9 M if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{! m2 w" |3 E3 Q/ D5 g4 C ?
SaveData( new Array(0) );0 T: Y0 h7 u" n% E8 o
}' ^$ o4 G$ X& `. C8 U B6 Z) x
}
! _. b$ w* t4 o+ |3 R. k# J$ R; [app.addMenuItem( ...{
5 ?: o3 N" V! [cName: "-", // menu divider
7 D: F" O# ^2 @( @/ H* Q+ n) _cParent: "View", // append to the View menu
& L( T* g; d# DcExec: "void(0);" } );
( I& H1 r) W3 f2 _. l( d) oapp.addMenuItem( ...{
2 g6 G% G ` w9 f* {2 t* FcName: "设置本页为书签(&B)",. W) C5 ?2 P9 p
cParent: "View",- O( [: _% u* X9 B) x: Z
cExec: "AddBookmark();",$ B; f; ]) j. O3 G* |
cEnable: "event.rc= (event.target != null);" } );
; C" u( s5 s2 q& ]2 I/ {( [app.addMenuItem( ...{7 U9 y; d- i" r# y" I+ v
cName: "转到指定书签(&T)",
0 s: x% i p" M( [cParent: "View",
7 R) [5 d* k- A$ P! LcExec: "ShowBookmarks();",
P7 Y9 E3 x- I" O; S1 BcEnable: "event.rc= (event.target != null);" } );
* u4 M0 K& a8 N7 \6 K//cEnable: "event.rc= true;" } );
- `* u6 T% c M9 c* K4 G2 Happ.addMenuItem( ...{# G1 n1 p q8 c% f Z
cName: "删除一个书签(&D)",* i4 N8 ]$ a% V2 I
cParent: "View",
' c9 h2 k% _- k. E4 N6 ycExec: "DropBookmark();",
' u8 e. f1 u: m1 u" }cEnable: "event.rc= (event.target != null);" } );
0 d' N* I' i b5 `9 _app.addMenuItem( ...{
- T2 R. z( o3 @" y* ocName: "清除所有书签(&C)",
6 L6 s6 r4 A- @- p ucParent: "View",% g; {2 W/ K$ @3 s9 p. w: w$ q
cExec: "ClearBookmarks();",
Q8 Y- Y& O& j. }0 }1 l, r- lcEnable: "event.rc= true;" } );$ ^5 s' C3 m, Z5 d7 j) c
4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下& W, [- V: M- H7 V& ~
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
q4 y- ?: w2 L" K" A2 w/ n+ W$ r; Y- O- O' l2 {' \
% w$ ~) [3 p3 Z) _6 B' o4 j
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|