TA的每日心情 | 奋斗 昨天 10:28 |
---|
签到天数: 2370 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法8 v" s ?5 c5 I0 t
1、打开编辑的首选项项( }) j) l2 B# D3 b& S6 G
4 o6 N! W6 G9 W8 Y! ?1 W0 r7 t, P2、确保下面的选项都被选中
- y+ N$ s. Y4 z4 u
* `( w w; Y: F9 o& w6 m" K$ N5 |3 把下面的代码保存为一个bookmark_page.js文件
, `; ?; `; ?# G' c) x9 `( b// bookmark_page.js, ver. 1.0
0 C \3 e) D$ H: p// visit: www.pdfhacks.com/bookmark_page/4 Q# Y/ o( R' s. L$ M% W7 s$ y) Y
// edit:cjs 2008-02-17 4 e% n" J4 e$ l, E- L8 ~- P
// 1 修改为中文标签& R! v& U1 D( ~* B+ X/ X. j
// 2 设置书签时可以自动获取当前的书名
3 G. w; b* x2 ~! j# Y// 3 自动获取当前所在的页码与总页数,方便查阅
6 X5 z0 ^# U, o0 M7 ^6 @8 h( n// 4 实现更多功能可以参看Adobe Reader的SDK
1 u$ M9 z% C, l( `/ f6 {! a9 @8 x
u* F$ w% i& j2 X; Q// use this delimiter for serializing our array
4 m) p6 t/ N" N; U4 Lvar bp_delim= '%#%#';9 m% @5 e* V3 u
function SaveData( data ) ...{
* X9 d/ s4 C, A% g( f8 }8 b4 z5 k // data is an array of arrays that needs# b! {! ^0 n+ |- p {4 s6 `
// to be serialized and stored into a persistent+ T& A2 \. o6 A6 L
// global string' q7 C. w; ]4 Y% N+ v
var ds= '';
1 f T2 C3 t1 s4 @' u& @ for( ii= 0; ii< data.length; ++ii ) ...{
4 [4 q( ~; g8 w0 z7 a& u( y( H0 y( c2 A for( jj= 0; jj< 3; ++jj ) ...{3 u) {4 m' b8 w. X" o
if( ii!= 0 || jj!= 0 )+ _8 Q) i, c. y7 i: W0 G$ x
ds+= bp_delim;' O+ n! c( e2 q( ]. {1 Q
ds+= data[ii][jj];
, T, A1 j% V3 G# ? N, K }" c- K) x! ?1 ^' l4 O
}, z" }, A. H" x6 i
global.pdf_hacks_js_bookmarks= ds;
. S, q) q& h6 b: [ global.setPersistent( "pdf_hacks_js_bookmarks", true );
# u: b% g: n& @}
0 K) D/ N; l1 |: m! y @function GetData() ...{& @3 A" F% r9 H) d7 Q! S
// reverse of SaveData; return an array of arrays
0 K, o7 M: T* F5 F( x if( global.pdf_hacks_js_bookmarks== null ) ...{
" ?7 V$ a# h9 v& I+ N return new Array(0);! p' f2 n% W/ {% F# ?
}
- G8 w8 t9 I4 }6 S6 ^- m- s; f: I var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );
; Y, q# t1 s l4 Y+ |6 C3 { var data= new Array();
9 a" n) F5 x" F: h! Y for( ii= 0; ii< flat.length; ) ...{" ~8 \) ~) B5 W" N
var record= new Array();0 |; T: a8 W5 e+ H7 D6 \( a2 C
for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
# E! D- j9 r0 N D) Z7 } record.push( flat[ii] );
$ W# x( y/ G# v+ R* _# H% i' J5 C }
V% H6 o" H. j if( record.length== 3 ) ...{
9 a9 n# k8 U0 L5 Q# @) n data.push( record );
1 Y, ^/ \% Q3 I' f& x" C O }/ Z. H* ~/ x2 w) Y: e9 ~4 U
}) U9 [! t- B" K# y& M+ I
return data;2 X" i8 m3 d1 B0 \& E
}" I: A) j: \6 G4 Y, F5 z
//Get Current Date% u; N$ c! Q4 W# B0 P
function DateNow()...{
6 @8 A0 s1 D B G4 \$ p var d, s ;
! B* U$ E! k2 X. ~) [$ R d = new Date();
6 i' Q2 a# U# x* C. v s = d.getFullYear()+"/";6 f. F/ |, P; Z
s += (d.getMonth() + 1) + "/";
8 Z& [# r+ }+ o6 n! z s += d.getDate() ;) J" U. ^" x5 u# j$ _
/**//*
& I% ]7 t! \# T! }; i/ U) V s += d.getHours() + ":";8 D8 ?( _7 }1 U) d# Q
s += d.getMinutes() + ":";) r8 w; o5 R' z( f6 A2 J
s += d.getSeconds() ;2 P- e/ I; E: S+ {
*/
* W) F: f1 Q- c return(s);" n3 a0 Q; k* p/ k2 \0 K1 G7 h5 I
}2 |) u/ u6 B" t/ E# r; h
! b3 [$ z9 {6 @# V0 ^function AddBookmark() ...{
7 D+ F" y, b9 R# H0 `4 i // query the user for a name, and then combine it with
: o7 n3 w# n4 C/ c // the current PDF page to create a record; store this record
, F5 Q7 e% ~) ~2 j var thisfilename=this.documentFileName;4 m3 j* k o! w- X4 Z2 t$ Q
thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf(".")); H. Z4 c8 f* ]) q( g% Z" r
var numPlugInss=this.pageNum+1;% X6 |/ C# @! G. S) R+ J1 {
var currentdate=DateNow();( f* s' R* r( G
var label= : `1 Q+ H5 E8 B; D
app.response( "书签名称,可以修改以便于记忆:",
. q4 @9 R$ G3 G- Z9 Z/ I6 n8 X6 q: r "书签名称",' k6 e- }4 g+ ]: D/ I' F% }. }
"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,
6 R* y- X- z5 i1 p* o: w false );, U) H4 b( b/ i
if( label!= null ) ...{' [1 o& I0 l6 u
var record= new Array(3);, f; Y( Y% ?+ E4 x* t! U) `
record[0]= label;
% _4 W% m6 m2 X* @) g record[1]= this.path;8 J2 H- {0 a$ j4 A6 T5 }; E
record[2]= this.pageNum;
, b7 ?- r- I' g( @% K1 C- i% C data= GetData();
, h6 n# Y1 V6 P4 q1 G data.push( record );* [4 c. H8 z2 f
SaveData( data );8 I& X' [/ @# R
}
' {. J4 P4 r3 T) N6 a4 ]; e}
% H7 Z0 n* r6 ~( ^function ShowBookmarks() ...{" _' [' S: C, S0 P
// show a pop-up menu; this seems to only work when
/ m7 U8 y4 }! _, }8 n // a PDF is alreay in the viewer;5 ~/ V" `3 @+ t
var data= GetData();" f' c0 {- a& N) R. ~
var items= '';
; `% H0 i+ z5 @# W' W% Q7 y4 } for( ii= 0; ii< data.length; ++ii ) ...{
6 k! ]: h' p( @! m4 h1 ?% L( i if( ii!= 0 )4 g0 K" t% X; ?0 I2 n. k' J& X3 ]7 i
items+= ', ';( @ @, u1 C" p1 m+ a
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
. Y8 }; ~9 C( T5 q) S }; \- Q b% I) @( Z/ z% C4 o
// assemble the command and the execute it with eval()
7 S- |( G) i( w9 M3 E0 F; r var command= 'app.popUpMenu( '+ items+ ' );';& u/ @/ p& E6 c- n5 d$ U) G
var selection= eval( command );
8 \8 m/ ?1 [' [) X/ J+ C if( selection== null ) ...{$ L! D0 D. S5 O- L6 i6 P
return; // exit8 {9 ~0 {2 J$ U- i9 n, u
}4 F9 ^( J5 b: n- C: W% I
// the user made a selection; parse out its index and use it: |% ~1 ? \0 C9 P, P
// to access the bookmark record( Y# e2 i( U: M0 o; r$ @4 _) k
var index= 0;
- E# J7 O9 s! q2 ]2 o( q // toString() converts the String object to a string literal
0 b1 j! X' O. h) T5 } // eval() converts the string literal to a number5 c" H0 a$ f# z6 v* E! S" U' |
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
% F$ k2 ^% A# W4 J5 q& p4 ] if( index< data.length ) ...{
2 D5 c$ G- \0 N& G1 a" Y4 t try ...{6 t; {* I, ~4 ^3 x3 v
// the document must be 'disclosed' for us to have any access( E5 y0 Y7 J; U3 ]3 [" g& j4 \
// to its properties, so we use these FirstPage NextPage calls @4 E$ G# n/ p1 x+ a
//
( [ m( U6 y5 S app.openDoc( data[index][1] );
6 b& D5 _4 u7 W$ D app.execMenuItem( "FirstPage" );
- Q: z- D y7 j9 D, H for( ii= 0; ii< data[index][2]; ++ii ) ...{0 s" \! A" _/ X' J! j
app.execMenuItem( "NextPage" );& j1 d% c" p0 u/ R6 M/ x" l
}& z! @ G$ c. Y7 G
}
' W" }( h% z, H9 l catch( ee ) ...{1 b; A" f) c7 S! g3 y3 \1 B
var response= 1 K# u R! u* Y" _3 C
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");/ ^" k. }- @2 V3 ^
if( response== 4 && index< data.length ) ...{
8 U9 Q1 s+ _0 h0 B1 T1 Z7 @ data.splice( index, 1 );
4 x/ m" P) c9 }) a$ M+ w SaveData( data );
% \5 q7 t! ^. r }
1 }! ^2 \; a) K# v- ]9 n0 l3 X2 f }
' ^, _3 Z: @0 p9 K- K }
" L1 z* ?1 X! O- p7 N( c. U7 w( ~}2 Z$ f. C J2 j5 ]1 C
function DropBookmark() ...{
[ K: ?$ t& j+ _ // modelled after ShowBookmarks()1 D5 Z' \! n1 X0 P7 y0 s) l. D
var data= GetData();; w, }0 E# g2 ^/ {6 G: ~
var items= '';0 P9 j C: V* E
for( ii= 0; ii< data.length; ++ii ) ...{- C) Y- S8 Z. T7 s6 K6 j
if( ii!= 0 ); X3 L: I( a" K% r. i- V4 v
items+= ', ';, ]% N$ K1 S8 \. W
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';3 W: a0 m" h4 `: }" ?0 x% z
}
, G, j' L+ s4 T var command= 'app.popUpMenu( '+ items+ ' );';
2 t7 W& o# M( u) ]3 Q9 e# Z var selection= eval( command );
/ S$ J5 l1 o3 G if( selection== null ) ...{
5 G& A! Y6 N7 p/ S return; // exit
' ]" ~" h$ ?8 A, e; f+ S3 { }; K7 Q- ?- W5 k8 R9 O8 a
var index= 0;
+ W9 w2 t: `. s index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
4 z# ?+ r+ h& L" O$ G if( index< data.length ) ...{
+ B" M% m+ ?9 i7 u' ^8 ?. ^1 X data.splice( index, 1 );$ A4 S' ~, X; R1 i( z. K t- P, J
SaveData( data );
" G0 a0 [" a" ^* P/ C/ z F }
) x% v0 w% t6 T9 `7 q5 Y/ ]4 L}1 y4 \1 J; \- P/ G
function ClearBookmarks() ...{4 d) K' |" K5 T
if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{
1 \! I2 ^# A" s SaveData( new Array(0) );5 r H% C1 N: q }4 V3 ]
}0 W1 E- N4 O# `/ k: \
}; b. S& s8 g7 ~0 F
app.addMenuItem( ...{9 ~" |5 [7 r$ N6 B+ S' x
cName: "-", // menu divider
! n: E K. ]1 x2 r' p! l5 \ DcParent: "View", // append to the View menu7 B. Q" M* w6 c8 R$ ^9 k
cExec: "void(0);" } );5 O& `+ B( }; u# z8 Z t" r
app.addMenuItem( ...{9 g9 o. q0 N+ D/ W( j8 Z6 u
cName: "设置本页为书签(&B)",
- l& k2 u9 o- _' Q9 \) K4 RcParent: "View",1 s3 f( k: j4 \* c! i
cExec: "AddBookmark();",
- v; W- `" Q- k( Y! ycEnable: "event.rc= (event.target != null);" } );) o$ o" ?. B+ |' J7 J
app.addMenuItem( ...{
, A$ B. p4 s% B2 h% N; b$ W2 T# kcName: "转到指定书签(&T)",/ I0 j, ]9 o- S- U) }
cParent: "View",
7 J; P3 p! U f% McExec: "ShowBookmarks();",
- t& K: o, I( Z& B6 UcEnable: "event.rc= (event.target != null);" } );: \* ]; N$ |4 _6 n
//cEnable: "event.rc= true;" } );1 C0 U! w) o+ K% d, y
app.addMenuItem( ...{' D r/ T7 u M5 r. S
cName: "删除一个书签(&D)",
+ q' E0 M$ a' [5 z. i) ~cParent: "View",
% a2 e4 y& N9 P' |# l/ hcExec: "DropBookmark();",* \ n2 a2 P ^+ u7 Y9 g1 h( b
cEnable: "event.rc= (event.target != null);" } );8 m ]: V C% C# k2 I! W6 o
app.addMenuItem( ...{
8 R; E9 Z) ]9 qcName: "清除所有书签(&C)",$ k, t4 K' f: d
cParent: "View",
; L( O- c! f" p' c0 XcExec: "ClearBookmarks();",; z5 ~; F# T) L2 K0 M/ }# z$ X
cEnable: "event.rc= true;" } );
* I5 ^+ d3 K7 V2 R/ E4 {4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
4 |4 ^9 S) L, N* A8 }; _5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
1 r/ o% A- |6 L' K7 f
) T9 V/ o% M' Q
7 v" D( q i# _2 D1 p' v8 l本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|