TA的每日心情 | 奋斗 3 天前 |
---|
签到天数: 2383 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
/ o9 d* G" ~) {" u0 c0 J1、打开编辑的首选项项
5 y: t F: T' F$ u7 F2 t% @5 d+ a) U7 o+ C8 V- H: Q% J( O
2、确保下面的选项都被选中. V( M& D1 X) c5 S4 H
0 G$ V8 G% I, l0 M3 |* Y; I3 把下面的代码保存为一个bookmark_page.js文件
( m+ M0 a2 a" N// bookmark_page.js, ver. 1.02 g4 [7 V5 D, {! G* i- S
// visit: www.pdfhacks.com/bookmark_page/+ D! X1 F5 ^0 `* R
// edit:cjs 2008-02-17
; }2 l: M O9 ^7 l5 K' c1 H// 1 修改为中文标签
& d) G: `& c3 @! Y8 U// 2 设置书签时可以自动获取当前的书名
/ M1 B1 C* F W! W1 } b4 u, I, Y// 3 自动获取当前所在的页码与总页数,方便查阅
( B; v) `9 n4 I// 4 实现更多功能可以参看Adobe Reader的SDK
# t9 J# A. H& [2 h9 ]) { M6 {
E C4 X1 z7 h* g+ l// use this delimiter for serializing our array
0 a! b$ p* J7 U; Lvar bp_delim= '%#%#';7 |: |' {& \) b L" m
function SaveData( data ) ...{: ~: H+ L) n4 {! V3 q
// data is an array of arrays that needs, v* `7 G) F* Z+ R" a2 N0 ]
// to be serialized and stored into a persistent
* j* A; [/ l6 M // global string8 q9 h3 O7 I8 M
var ds= '';$ U4 {' @* j# ~+ T! u6 _
for( ii= 0; ii< data.length; ++ii ) ...{$ |8 p. s1 t# ~* f+ @7 m
for( jj= 0; jj< 3; ++jj ) ...{4 ?# x3 ]' b6 h! X
if( ii!= 0 || jj!= 0 )# M7 Z5 q9 A- K! e/ n
ds+= bp_delim;) `, U8 s- r! [: j& g! v
ds+= data[ii][jj];0 j# {) b" Q! L: |3 N
}
( E. i6 [1 t0 g5 C* b) T }1 H3 @$ w& }3 o0 E
global.pdf_hacks_js_bookmarks= ds;/ L: J7 s( D* y Q3 Y" Z* n+ A$ \
global.setPersistent( "pdf_hacks_js_bookmarks", true );; z {- R, A3 T* Y
}
0 H5 C9 p: X" T* Qfunction GetData() ...{
, ]0 ^% }2 x6 m, i# { // reverse of SaveData; return an array of arrays% L: J# v b% y n- z
if( global.pdf_hacks_js_bookmarks== null ) ...{8 k5 p) s; J: v, r1 i$ e
return new Array(0);6 v, i0 q, W1 w8 u; [
}0 P7 o. ^8 _ b" j* U
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );# Z8 x- t; g* x9 u+ J9 |$ y) Z
var data= new Array();. Z" f/ t! V4 L! \
for( ii= 0; ii< flat.length; ) ...{
, K2 A$ a& V8 v var record= new Array();5 _) F% Y% E& W7 \
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{! d" o+ i+ |) U' M& h( x3 T+ Q
record.push( flat[ii] );
; M' `- A! d' t0 P+ n }" I" J6 w& l. D2 b; F0 @8 Q" m
if( record.length== 3 ) ...{, u) |, G! S) u9 ~ a
data.push( record );
' {6 B8 T1 W2 K* \( f }
8 T9 S R' O& T/ r p }
0 q# t& H* ]0 }8 g return data;
% g4 N. p/ W5 T3 C4 i1 v/ Y; Y}9 Q/ x" c* o, f$ [- P# i
//Get Current Date
, c s& ]( V. ?0 y) bfunction DateNow()...{3 ]! S0 v z6 P4 `0 R
var d, s ;6 W% c) A7 x0 H/ ^' h1 o
d = new Date();3 Q% o! R( Z1 Z
s = d.getFullYear()+"/";
1 O- l6 a! ^$ N& G s += (d.getMonth() + 1) + "/";. N$ d Z0 \+ k$ Q5 R
s += d.getDate() ;4 u4 P7 I! y5 b
/**//*6 s6 R! s+ w! G7 u% ]* n" P" ~6 z# P
s += d.getHours() + ":";
( c- i1 Y2 ]5 c s += d.getMinutes() + ":";1 }! q- R( G: ]5 F$ V
s += d.getSeconds() ;
; {1 m) H! p* Z! R' w8 t% W */
& o2 U" }7 b( p8 f* a% W return(s);$ b' \. N! H/ p5 S
}. l7 Q7 \+ U1 l8 \9 j) {
$ N% b* P/ p0 h! u
function AddBookmark() ...{
, X% ] }/ j3 ^) u1 e5 k$ y% U1 J // query the user for a name, and then combine it with# a6 v' k' L r; C- b- s
// the current PDF page to create a record; store this record
% |) ?' g- n' ~7 e* C& B+ a8 n' L var thisfilename=this.documentFileName;
2 ~ Q% C2 x% H1 ^8 q1 b |+ i, } thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf(".")); M1 q" m/ Y' T+ X3 _1 {5 }
var numPlugInss=this.pageNum+1;7 \( w% p9 o, c1 h4 E! r
var currentdate=DateNow();
7 U: o4 w( X& I- h7 P var label=
x, R1 c+ a9 O/ ~( P. l& d app.response( "书签名称,可以修改以便于记忆:",; X0 ~5 s; S" F" U- E) O, U; [
"书签名称",
" G" \5 e% j( X, O6 ^- u% Q+ U "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
: J7 i; S1 J% F L% W9 e3 _ false );/ p: @9 g1 E* i3 f4 u
if( label!= null ) ...{, ]7 R+ P6 T+ |2 q
var record= new Array(3);$ U3 [ o0 u4 G& }2 o4 Y
record[0]= label; }3 f# @) n5 |5 [9 j9 w. v
record[1]= this.path;
8 T8 i0 B8 n) `9 Y" G2 @ record[2]= this.pageNum; g" I0 @( N; `2 d2 E) {
data= GetData();* J* H$ N9 }7 [
data.push( record );
4 x: ~3 d: {6 ] r; E SaveData( data );
4 }; k Q! k* e3 _' p }
8 e8 w! F! z [3 b6 N}
5 l2 n- W E7 Y' S# kfunction ShowBookmarks() ...{
8 z% L9 g1 k8 t/ y // show a pop-up menu; this seems to only work when
* q) i' |9 y& A5 s // a PDF is alreay in the viewer;. E, D" L0 j" k3 \. H1 }
var data= GetData();2 d T6 X8 Q+ _; I8 {; I+ k8 J- B3 ~
var items= '';$ p& ^4 \% k# Q. U5 F
for( ii= 0; ii< data.length; ++ii ) ...{5 Z8 w; m! l5 a8 ]+ }# Y
if( ii!= 0 )
% T2 M2 J7 J% l items+= ', ';: Z) [' }9 H7 n0 l+ ]/ n! X
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';0 [9 l* s u1 { \1 z
}* F# p: I, l4 F2 R) E) i* g
// assemble the command and the execute it with eval()
% m+ Y; f* M1 Y' r# I3 n1 ~2 E2 A7 { var command= 'app.popUpMenu( '+ items+ ' );';
+ w9 t z6 j% x var selection= eval( command );
& t3 r2 s _& J4 n$ w6 N if( selection== null ) ...{
# M9 D3 ^' x! |. e5 W7 `( y( x' a return; // exit, Q( S% h7 ^5 g% N4 {$ q3 B) I
}& g& j! L4 e! O- h1 }
// the user made a selection; parse out its index and use it0 S" o9 f! K. \- @$ N* F9 K
// to access the bookmark record
5 n; o6 `9 |8 t! l0 } var index= 0;; V; H. y7 S' M0 Y, n! ~" q
// toString() converts the String object to a string literal
- p* L# N6 u! s* I, E( C // eval() converts the string literal to a number' r! v6 }7 W: b7 Y; r+ g0 y, U
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
2 } ?! K \$ i0 }2 {2 |4 i. } if( index< data.length ) ...{
# B! f9 k% V+ w try ...{ m* R: D8 L* v( U
// the document must be 'disclosed' for us to have any access
. B9 P% m. r. H6 P3 G# ] // to its properties, so we use these FirstPage NextPage calls" i& o' H4 y" G1 `
//2 s6 }. c' X6 A$ d% c
app.openDoc( data[index][1] );
8 T+ _( a' w, D app.execMenuItem( "FirstPage" );
& `# V @% O2 e, W for( ii= 0; ii< data[index][2]; ++ii ) ...{+ k0 j- Y* M" g& g
app.execMenuItem( "NextPage" );: N% C1 Z/ E* t) y2 A8 R+ j
}
& y6 W/ V8 N0 ]" X) O2 O }* n( l& r4 \! M) j: y; _8 \. `5 c5 L, l
catch( ee ) ...{
7 V- F+ x) _! T; p+ Z var response=
8 F c% \: l* o) [6 V: \! g* X8 ] app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");$ ?2 s! j: h: v9 \0 N
if( response== 4 && index< data.length ) ...{5 |7 z9 Y6 m# _2 L8 J* Z3 B* [0 g
data.splice( index, 1 );# F# c( t) u3 R
SaveData( data );; ` O3 V7 G" G* }7 h4 A: @9 x
}
; T. j+ Z1 x! b3 P) Z( q }
+ R3 c# O# ?" F- }+ o }) h+ l$ @! [, y8 U
}: E0 {! c3 m: r( R* L
function DropBookmark() ...{
" q9 {2 o- Z) W // modelled after ShowBookmarks()
g) ^" X0 k7 ~# @ var data= GetData();- R; C2 {3 W4 h$ Z1 c- d& e
var items= '';
3 N! `, _, ] x5 A2 F# d for( ii= 0; ii< data.length; ++ii ) ...{0 Q( i; v7 W5 S& ^% y7 _7 v% ?
if( ii!= 0 )
% G* k7 u; H7 l! e: y items+= ', ';
- H- d6 f( O! S8 y& W, B) O items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
4 a) n1 K& q3 l& N7 r r( k! e+ Y }
; ^3 `7 D3 G9 a# B9 x6 W var command= 'app.popUpMenu( '+ items+ ' );';
$ M5 W# g4 B5 {* C! j. E; r var selection= eval( command );
% t3 F7 B1 t7 M. d' i if( selection== null ) ...{
3 l( _2 G) M6 ]' c; n0 @ return; // exit4 p0 x8 i5 m8 P1 w( p5 o1 e
}
6 \3 R# L0 m& X7 z' q: |4 E var index= 0;9 k! O! q& M8 {4 k, R
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );9 x1 r2 e# w2 C1 {: f+ y
if( index< data.length ) ...{
' b# T8 P: `8 J+ v9 G data.splice( index, 1 );
) H5 }5 q* l& c/ q2 B, z+ R3 h' A SaveData( data );
" n) `6 j, |6 K! ` }
4 G, b0 V6 h/ k9 h: v}( F% w# H. f) ?, d- T; ]; S2 ^
function ClearBookmarks() ...{/ r1 h3 M% c) D Z- _0 u3 [/ s
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{: @9 N2 {5 K4 c% g5 p+ M w9 z+ n
SaveData( new Array(0) );( k# f! b4 |" ^' G, `* |5 L
}1 {5 w! v. _7 y( w* ?6 G1 _) C
}
# c) a5 _: S: \app.addMenuItem( ...{" o% P3 U$ D/ o# o
cName: "-", // menu divider; Z6 s4 f4 U5 x& F r, d
cParent: "View", // append to the View menu
0 z5 I0 ]% [% n+ \4 u+ ScExec: "void(0);" } );( V3 d' e9 u* |) [, J+ w
app.addMenuItem( ...{8 r6 g* R: g( W2 i9 [3 x2 G
cName: "设置本页为书签(&B)",
& G9 A! w6 {; ~$ a- HcParent: "View",6 _- f& d/ L! z* U
cExec: "AddBookmark();",
% d* r0 y+ E/ s8 H" O0 s% g# o! i+ H0 bcEnable: "event.rc= (event.target != null);" } );/ N6 ]* t" o+ E+ J
app.addMenuItem( ...{5 k8 N; [4 i6 L
cName: "转到指定书签(&T)",8 L2 G% u: P7 W( ?
cParent: "View",* Z) h- H# R7 A W
cExec: "ShowBookmarks();",
) P2 K+ m+ u5 m% J. {cEnable: "event.rc= (event.target != null);" } );6 z. r8 U1 l: C. w! u
//cEnable: "event.rc= true;" } );! w( m7 [9 w5 ?6 d# B
app.addMenuItem( ...{ F! V0 R# x3 z$ V0 X9 j' N
cName: "删除一个书签(&D)",
1 h W* o0 y) x' JcParent: "View",
5 N3 x2 K; c+ B- pcExec: "DropBookmark();",
3 Y5 _& G( M8 {) XcEnable: "event.rc= (event.target != null);" } );' w, r2 F- S$ o3 V
app.addMenuItem( ...{: \: i& }7 L. l% `- i
cName: "清除所有书签(&C)",
1 k" f0 c+ ?: \' acParent: "View",
! }9 f% ~, O0 N6 f7 R4 RcExec: "ClearBookmarks();",* p7 E: f: l V% C3 I$ E
cEnable: "event.rc= true;" } );
& V$ e* W; N3 L% H# ? f4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下' K! r( q9 g8 @- i! M6 [1 ?) V
5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
% o% _ l9 T0 M) @6 I4 k' s- w+ @ ?" Y5 U$ g) L: w! x' C7 u3 \
' Y q/ D( b& q5 ^% h2 L
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|