TA的每日心情 | 奋斗 昨天 14:14 |
---|
签到天数: 2401 天 [LV.Master]伴坛终老
|
最近经常看一些PDF的电子文档,痛苦的是Adobe Reader竟然没有提供书签的功能,每次看完之后再回到上次看的地方都很麻,到网上一找,还真有人就做了PDF的书签,下载一试效果不错,于是参看了一下Adobe Reader的SDK,修改了一点地方,以更方便的使用,下面是程序的使用方法
" H" e7 e0 r, ]$ I' E1、打开编辑的首选项项9 s3 j1 b) T7 l0 W% i
2 K( K) f# Q) V1 S5 |! ?4 m, Y6 F2、确保下面的选项都被选中
# |0 b( J4 l' V" n/ b a
' o7 W3 x7 I. y' w' I1 n3 把下面的代码保存为一个bookmark_page.js文件
! Q/ t7 L( Q1 q- H// bookmark_page.js, ver. 1.09 x6 j( e+ e2 k7 ~ J/ t2 H
// visit: www.pdfhacks.com/bookmark_page/) ]& j; \* y. E' O: A! `
// edit:cjs 2008-02-17 ; {0 t8 {7 ^' H) Z5 ~
// 1 修改为中文标签" Q2 b) V2 s7 D5 ]2 I( w7 n0 p
// 2 设置书签时可以自动获取当前的书名0 T9 Q0 T) u5 u& \1 U4 `
// 3 自动获取当前所在的页码与总页数,方便查阅
1 i4 W- ~# z$ M0 ]& G5 I// 4 实现更多功能可以参看Adobe Reader的SDK
' ?3 }# y: h$ Q2 K5 h. Q! e* S$ `, {$ Y2 N- S7 R
// use this delimiter for serializing our array+ Y( g6 n1 V+ l2 ~4 U6 }% B
var bp_delim= '%#%#';" U. Q! v+ \( Z( o
function SaveData( data ) ...{
8 K1 j+ h/ }' y' [+ I4 [ // data is an array of arrays that needs( u9 @5 Q7 g+ T
// to be serialized and stored into a persistent) h4 u) I+ ]+ ~7 s0 u# Q, J
// global string0 N, b' N$ g# U; _7 ?! j Y
var ds= '';# `( G% W& p/ r; y$ w
for( ii= 0; ii< data.length; ++ii ) ...{, I& j; L7 f$ q" o& J
for( jj= 0; jj< 3; ++jj ) ...{6 p. v$ O, Y v6 j: Z
if( ii!= 0 || jj!= 0 )7 f: ^! U5 d) J( m. f3 |& N/ W
ds+= bp_delim;+ b% J7 `* v% y! X- v
ds+= data[ii][jj];- `* m# T, R/ v) @0 T3 s% X
}' ~/ G; Q, b6 M" ?1 }1 Q5 y' x
}
8 t& c( p* t$ d global.pdf_hacks_js_bookmarks= ds;
, \+ j4 Y/ |# c9 @( z: D9 T" } global.setPersistent( "pdf_hacks_js_bookmarks", true );
" H! C0 y2 j- {, @}( M( H/ r2 f; p
function GetData() ...{( O0 ~$ e* [) p# k8 H/ b
// reverse of SaveData; return an array of arrays
% M; {7 i2 I' v* n if( global.pdf_hacks_js_bookmarks== null ) ...{
4 U$ y$ j9 Q8 m, d6 P) M6 N' K" a return new Array(0);
4 K4 _$ j3 z: g% w R* H( h8 o }- E n7 p1 I/ o+ o9 O. T
var flat= global.pdf_hacks_js_bookmarks.split( bp_delim ); A1 k/ t" B2 c C6 X
var data= new Array();
, |3 |4 Q6 k4 r% }2 u+ o3 S for( ii= 0; ii< flat.length; ) ...{7 B9 h7 v9 g9 R) M4 C0 I
var record= new Array();
) U2 i/ g; U* s% s% a; r; D for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) ...{
) u3 u: `5 G4 Q5 n9 n record.push( flat[ii] );
* a- }' h! T5 K. ^" ~ w$ F }
6 H) o- h4 S2 i! s if( record.length== 3 ) ...{
4 F/ g2 `2 t# i( p' \8 l | data.push( record );
. r Y. ]* `0 a8 k: z7 b* ^ }* S6 i* C, B* G/ F8 N/ V4 q
}
7 \* ^( ]0 Z6 \+ n- M return data;
) O f+ B& ~' b$ q8 Q0 U}
o; l' l: o: m( {; C! S. E- [' n9 q//Get Current Date
3 T& S8 k8 `9 h' G! `( V( T0 Gfunction DateNow()...{. Y" N" H3 m) K& h: o1 b0 m
var d, s ;
( o: [8 E. r+ S' C. v, h1 z d = new Date();* [2 @4 g7 R+ r( H
s = d.getFullYear()+"/";
3 M* `" E- o- h& n% k$ G. K s += (d.getMonth() + 1) + "/";7 E8 h' G! n9 Z) `4 T5 { _
s += d.getDate() ;
+ _# \3 w. o, M0 U/ C /**//*
) }/ U2 ~* n: S3 L6 R s += d.getHours() + ":";
1 G- Q/ g; M( } s += d.getMinutes() + ":";) a3 ^- {" K8 B4 v
s += d.getSeconds() ;
, b' a" J) f6 L' _ *// {! L/ w/ r; C9 z7 `
return(s);. Z3 R% \4 V# H5 V
}
% K9 Q" b# q& ^' ^/ X0 o8 z% y! n8 l) ?! ?7 W- B
function AddBookmark() ...{! y8 C9 f0 _- V- v+ C' ]
// query the user for a name, and then combine it with" |4 A" G0 [+ T0 X4 s: g }9 w+ e- Z
// the current PDF page to create a record; store this record4 P q, B6 E8 P/ S: c, y. C( W
var thisfilename=this.documentFileName;
1 s* g/ g; m. V1 r0 ] thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));
7 {, g/ U# b7 q9 U% H1 w var numPlugInss=this.pageNum+1;
Y4 H9 e3 m1 A2 f- I8 x var currentdate=DateNow();/ l% {- K2 C) b$ n) h
var label=
6 [; K2 m3 `* K; a( @9 ?/ O5 `4 \ app.response( "书签名称,可以修改以便于记忆:",
) ]! Q1 N0 e: {6 r3 ?: Y "书签名称",
* f# ?( R2 X* G' L* X. { "《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,. j" Y0 o: U) H' p; ?
false );
- n$ w) l# E' L& u. ?2 i* o" R if( label!= null ) ...{/ J. t+ C+ c) ]0 y7 Y" D: j
var record= new Array(3);
" G7 E' v5 q" w8 m1 _ M6 K/ l record[0]= label;
K4 W' i; t3 d2 ?5 n9 b1 R* ` record[1]= this.path; ?' m+ u: e+ j* n P
record[2]= this.pageNum;
7 A; _. I0 H C5 n4 p. J data= GetData();, P7 a e1 b9 q W( Y, F
data.push( record );4 y& u$ ?! S% l' Y7 }# F' w4 A
SaveData( data );
6 Y4 h2 w' e. I. S) _ }* x4 l* {( b& Q
}
; A6 d. f% h( c* w& f2 Q5 M% ?function ShowBookmarks() ...{
/ | X3 S6 R j) X8 [1 a: v1 G3 `5 a // show a pop-up menu; this seems to only work when0 T" D% W" h) ~$ K
// a PDF is alreay in the viewer;9 p4 X3 Q8 X" D' ]' {6 j3 D3 b( j
var data= GetData();& A9 J8 X4 W# Y9 t# ~% T
var items= '';
! C) J9 v& |0 X0 W* o5 w for( ii= 0; ii< data.length; ++ii ) ...{
$ w& [$ k& U" @ if( ii!= 0 )2 Q Z% Z, |& ~5 L2 @( a
items+= ', ';% p n" F! E& S" d& ~$ v. h
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';7 C# p8 \% I5 s, M( c
}6 n, g$ H, J' h+ u7 @. ~
// assemble the command and the execute it with eval(); `, _; a- n; U x& n: N+ v$ I3 T% Q
var command= 'app.popUpMenu( '+ items+ ' );';
' [" ~8 @ y% m var selection= eval( command );5 F+ b7 H+ y6 _8 p) H, w, i) O8 y# A
if( selection== null ) ...{
+ D$ X K, t3 ?, f: F7 E" ~3 G1 U6 }6 W return; // exit
2 n! w' e3 l F& w3 g& l }
/ {' x# |! H. q& B3 M' M // the user made a selection; parse out its index and use it, n& x6 `% a& ~; ^2 L
// to access the bookmark record
7 o, q( g f3 f, ]0 \6 R var index= 0;% q2 K' T& C! j" Z" B, A1 x5 C
// toString() converts the String object to a string literal" w6 f( }* q( p
// eval() converts the string literal to a number+ [6 z" R$ S/ w
index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
3 {- z- o9 b6 }& D, B. o if( index< data.length ) ...{3 Q( [0 h# u3 ^; m" a0 |' N" h
try ...{* T# O0 I* \' o8 b7 o
// the document must be 'disclosed' for us to have any access
8 [+ r3 G" W k. ~. r B // to its properties, so we use these FirstPage NextPage calls
, J8 h; o$ |2 t" h% u1 K // n: a* S7 I. K2 {0 R! B
app.openDoc( data[index][1] );1 m* @' D: Z6 ?" \ J
app.execMenuItem( "FirstPage" );' V9 u0 s) m, m$ `" [
for( ii= 0; ii< data[index][2]; ++ii ) ...{
4 T% y0 W/ O8 N4 h! z app.execMenuItem( "NextPage" );: h/ n {) }1 Z; s8 v
}
4 l4 I. h$ a9 A6 a4 A' U }+ |' m7 U, X1 P+ K; l# @1 a' b" v2 D
catch( ee ) ...{, ]( I. O8 D4 H/ |4 O6 b% v
var response= 2 C/ T _2 s" d. H- b
app.alert("打开书签错误. 是否删除本书签?", 2, 2,"删除书签");
# d! b9 F! x" U+ b7 s( O) | u- f if( response== 4 && index< data.length ) ...{" b7 e5 Z( b2 U; X8 x9 M! s8 P
data.splice( index, 1 );& `% A5 q% k2 ~9 h; Y8 y* Z5 @
SaveData( data );
! }: i1 b* d/ M) U' {1 e& u8 f }2 A( f3 ], u+ M9 l! d6 K \& r
}
( Z, A# b7 ?' \6 F# E; |2 ^ }0 {4 @5 ~. p6 C/ _, I
}
5 l, p$ R0 c# V. c8 _- I# ], Nfunction DropBookmark() ...{3 U, I4 Y: G' j5 B
// modelled after ShowBookmarks()
# R: ?4 j8 e8 r2 c7 t var data= GetData();1 }" A) i; B4 u' G4 P
var items= '';3 D& }3 v8 \2 f2 {
for( ii= 0; ii< data.length; ++ii ) ...{
6 L* F8 ~$ o C; S' B if( ii!= 0 ): e7 Y) K ^$ {" @5 @( L# q
items+= ', ';& B7 Y( m* M# g& J! _4 U6 @
items+= '"'+ ii+ ': '+ data[ii][0]+ '"';
" H) Z, Z: [* M/ O2 f* D } f% `, O* Z; p% C# N9 H
var command= 'app.popUpMenu( '+ items+ ' );';( h7 L; ~& h7 v4 L4 m9 w1 ]' w
var selection= eval( command );2 Z. Y) x S6 S
if( selection== null ) ...{
* R0 e$ G' n7 X) V1 r" h: W return; // exit2 t/ d2 ?' s# R& c8 h
}
1 A' w0 H! _( |# B4 z var index= 0;
! c; q& [% c# [, s7 } index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );
' a) f# p* O6 J6 ?6 ~& I3 S# K if( index< data.length ) ...{, f" \* A: B Z+ t* W
data.splice( index, 1 );
, l2 e- b) B% n/ \7 y6 F9 q9 l SaveData( data );
* B1 v/ y( l6 m1 j* U# L }5 M! m* u8 R- v+ z; |$ I
}
6 s0 J% c, f' z" i& E/ `function ClearBookmarks() ...{
2 m5 M o# k. m1 ]6 ^; m if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) ...{! ], T2 R6 g6 y$ O* m
SaveData( new Array(0) );
; d2 W8 S9 h" k5 J- |4 C" B; H }# F; _% ?+ v. i( U& L# z) _, O% O
}2 }; i' N" i; }% @9 Q
app.addMenuItem( ...{
: ~. m7 `$ i' L% S7 ^2 GcName: "-", // menu divider
4 f# k# b6 }3 ^ i6 @5 G# S7 c1 jcParent: "View", // append to the View menu
$ ^, i c6 k* F1 [' Z( pcExec: "void(0);" } );
2 {. ]/ J- M! Gapp.addMenuItem( ...{* c' r) A" d1 ^: B3 T
cName: "设置本页为书签(&B)",& h+ N+ O- a1 [8 f* ]2 p
cParent: "View",
" y. z6 D; T% {/ WcExec: "AddBookmark();",/ e6 Y: Q/ k+ |% T5 W+ z. n
cEnable: "event.rc= (event.target != null);" } );
6 o) T7 [0 K& U" ~2 `app.addMenuItem( ...{
* h2 V7 V$ t/ i! s& F+ ccName: "转到指定书签(&T)",4 P7 r/ E6 l# }6 |. ]
cParent: "View",
+ S' R! l. P2 x8 ^* qcExec: "ShowBookmarks();",' ^$ k6 p% X8 q' g: N: _
cEnable: "event.rc= (event.target != null);" } );
* o! v' D! ?: P- n6 {* C; [; c5 B6 P! U//cEnable: "event.rc= true;" } );9 d( z6 K0 V' z# k5 `* {
app.addMenuItem( ...{
% {, I! W9 S/ V- V! m7 C, CcName: "删除一个书签(&D)",) B2 X1 l7 t+ I x7 ^/ i
cParent: "View",
) U8 `. r* z) w2 U3 Z) L4 ?cExec: "DropBookmark();",$ A/ \% N% x# m. L/ g& C
cEnable: "event.rc= (event.target != null);" } );$ @) O6 B3 Q% @
app.addMenuItem( ...{
- T" `' S# A! p& q- ucName: "清除所有书签(&C)",
7 v0 i1 |% X4 e/ S3 |% S) Z0 V- ecParent: "View",! `: V7 [$ b$ v) {' l- M
cExec: "ClearBookmarks();",
* ~2 b8 V5 @) j+ Q$ E4 o2 @/ |cEnable: "event.rc= true;" } );
7 F" m5 ]1 V5 f b* M/ h4 o4 将文件拷贝到C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts目录下
' ]+ X& w2 _4 ?5 F m C9 y# z5 重新打开Adobe Reader,看看下面的图形,相信不用说任何东西,大家都会用了
* T( p3 D8 {( Z7 }, |4 {$ T2 T
6 J4 U8 p* i5 z* ~+ @6 ?4 L! w) O/ M4 |* k
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aohan/archive/2008/02/20/2108051.aspx |
|