给Adobe Reader添加书签功能

来源:互联网 发布:spring源码怎么看 编辑:程序博客网 时间:2024/05/01 07:52

 给Adobe Reader添加书签功能 收藏

Adobe Acrobat ProfessionalAdobe Reader都是Adobe公司的产品。前者用来编辑制作PDF文档,后者只能用来阅读PDF。令人郁闷的是Adobe Reader中虽然有书签这一项显示,却没有添加书签的功能。解决方法一是使用Adobe Acrobat Professional,另一个方法如下:

http://www.pdfhacks.com/bookmark_page/bookmark_page.js-1.0.zip 上面下载一个javascript脚本文件,把这个文件放到Adobe/Acrobat 7.0/Reader/Javascripts目录下。如果忘记了Adobe的安装目录,可以运行Adobe Reader,然后使用process explorer查看进程对应的可执行文件路径。文件放好后,重新运行Adobe Reader,就可以在“视图”菜单项的下面发现四个新增的条项。这四个新增的条项就是那个javascript文件的效果,它们能够实现书签的功能。这个新增的书签功能自然是不能和Adobe Acrobat Professional中的书签功能相比,但对于阅读文档也足够了。

下面是那个javascript文件的内容:

 

view plaincopy to clipboardprint?
  1. // bookmark_page.js, ver. 1.0  
  2. // visit: www.pdfhacks.com/bookmark_page/  
  3.   
  4. // use this delimiter for serializing our array  
  5. var bp_delim= '%#%#';  
  6.   
  7. function SaveData( data ) {  
  8.   // data is an array of arrays that needs  
  9.   // to be serialized and stored into a persistent  
  10.   // global string  
  11.   var ds= '';  
  12.   for( ii= 0; ii< data.length; ++ii ) {  
  13.     for( jj= 0; jj< 3; ++jj ) {  
  14.       if( ii!= 0 || jj!= 0 )  
  15.         ds+= bp_delim;  
  16.       ds+= data[ii][jj];  
  17.     }  
  18.   }  
  19.   global.pdf_hacks_js_bookmarks= ds;  
  20.   global.setPersistent( "pdf_hacks_js_bookmarks"true );  
  21. }  
  22.   
  23. function GetData() {  
  24.   // reverse of SaveData; return an array of arrays  
  25.   if( global.pdf_hacks_js_bookmarks== null ) {  
  26.     return new Array(0);  
  27.   }  
  28.   
  29.   var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );  
  30.   var data= new Array();  
  31.   for( ii= 0; ii< flat.length; ) {  
  32.     var record= new Array();  
  33.     for( jj= 0; jj< 3 && ii< flat.length; ++ii, ++jj ) {  
  34.       record.push( flat[ii] );  
  35.     }  
  36.     if( record.length== 3 ) {  
  37.       data.push( record );  
  38.     }  
  39.   }  
  40.   return data;  
  41. }  
  42.   
  43. function AddBookmark() {  
  44.   // query the user for a name, and then combine it with  
  45.   // the current PDF page to create a record; store this record  
  46.   var label=   
  47.     app.response( "Bookmark Name:",  
  48.                   "Bookmark Name",  
  49.                   "",  
  50.                   false );  
  51.   if( label!= null ) {  
  52.     var record= new Array(3);  
  53.     record[0]= label;  
  54.     record[1]= this.path;  
  55.     record[2]= this.pageNum;  
  56.   
  57.     data= GetData();  
  58.     data.push( record );  
  59.     SaveData( data );  
  60.   }  
  61. }  
  62.   
  63. function ShowBookmarks() {  
  64.   // show a pop-up menu; this seems to only work when  
  65.   // a PDF is alreay in the viewer;  
  66.   var data= GetData();  
  67.   var items= '';  
  68.   for( ii= 0; ii< data.length; ++ii ) {  
  69.     if( ii!= 0 )  
  70.       items+= ', ';  
  71.     items+= '"'+ ii+ ': '+ data[ii][0]+ '"';  
  72.   }  
  73.   // assemble the command and the execute it with eval()  
  74.   var command= 'app.popUpMenu( '+ items+ ' );';  
  75.   var selection= eval( command );  
  76.   if( selection== null ) {  
  77.     return// exit  
  78.   }  
  79.   
  80.   // the user made a selection; parse out its index and use it  
  81.   // to access the bookmark record  
  82.   var index= 0;  
  83.   // toString() converts the String object to a string literal  
  84.   // eval() converts the string literal to a number  
  85.   index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );  
  86.   if( index< data.length ) {  
  87.     try {  
  88.       // the document must be 'disclosed' for us to have any access  
  89.       // to its properties, so we use these FirstPage NextPage calls  
  90.       //  
  91.       app.openDoc( data[index][1] );  
  92.       app.execMenuItem( "FirstPage" );  
  93.       for( ii= 0; ii< data[index][2]; ++ii ) {  
  94.         app.execMenuItem( "NextPage" );  
  95.       }  
  96.     }  
  97.     catch( ee ) {  
  98.       var response=   
  99.         app.alert("Error trying to open the requested document./nShould I remove this bookmark?", 2, 2);  
  100.       if( response== 4 && index< data.length ) {  
  101.         data.splice( index, 1 );  
  102.         SaveData( data );  
  103.       }  
  104.     }  
  105.   }  
  106. }  
  107.   
  108. function DropBookmark() {  
  109.   // modelled after ShowBookmarks()  
  110.   var data= GetData();  
  111.   var items= '';  
  112.   for( ii= 0; ii< data.length; ++ii ) {  
  113.     if( ii!= 0 )  
  114.       items+= ', ';  
  115.     items+= '"'+ ii+ ': '+ data[ii][0]+ '"';  
  116.   }  
  117.   var command= 'app.popUpMenu( '+ items+ ' );';  
  118.   var selection= eval( command );  
  119.   if( selection== null ) {  
  120.     return// exit  
  121.   }  
  122.   
  123.   var index= 0;  
  124.   index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );  
  125.   if( index< data.length ) {  
  126.     data.splice( index, 1 );  
  127.     SaveData( data );  
  128.   }  
  129. }  
  130.   
  131. function ClearBookmarks() {  
  132.   if( app.alert("Are you sure you want to erase all bookmarks?", 2, 2 )== 4 ) {  
  133.     SaveData( new Array(0) );  
  134.   }  
  135. }  
  136.   
  137. app.addMenuItem( {  
  138. cName: "-",              // menu divider  
  139. cParent: "View",         // append to the View menu  
  140. cExec: "void(0);" } );  
  141.   
  142. app.addMenuItem( {  
  143. cName: "Bookmark This Page &5",  
  144. cParent: "View",  
  145. cExec: "AddBookmark();",  
  146. cEnable: "event.rc= (event.target != null);" } );  
  147.   
  148. app.addMenuItem( {  
  149. cName: "Go To Bookmark &6",  
  150. cParent: "View",  
  151. cExec: "ShowBookmarks();",  
  152. cEnable: "event.rc= (event.target != null);" } );  
  153.   
  154. app.addMenuItem( {  
  155. cName: "Remove a Bookmark",  
  156. cParent: "View",  
  157. cExec: "DropBookmark();",  
  158. cEnable: "event.rc= (event.target != null);" } );  
  159.   
  160. app.addMenuItem( {  
  161. cName: "Clear Bookmarks",  
  162. cParent: "View",  
  163. cExec: "ClearBookmarks();",  
  164. cEnable: "event.rc= true;" } );