首页 > 其他分享 >给adobe reader 添加书签功能

给adobe reader 添加书签功能

时间:2022-11-15 14:57:46浏览次数:88  
标签:index adobe app 书签 ii record reader var data

Please refer to 

How to Bookmark Pages in a PDF Document in Adobe Reader

个人喜欢两种方法:

1. 打开恢复上次阅读功能。

Edit > Preferences->Documents->Restore last view settings when reopening documents

2. 使用Javascript插件。

首先要打开javascript插件功能:

Edit > Preferences->Javascripts->Enable Acrobat JavaScript

                                                          Enable menu items javascript execution priveleges

然后把bookmark_page.js文件考到adobe reader所在目录的Javascripts目录下。

最后重启adobe reader。在view菜单下就可以看到添加、清除书签的菜单了。

bookmark_page.js

附上bookmark_page.js源码,也可点击上述连接下载.

  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;" } );
View Code

 

  

 

标签:index,adobe,app,书签,ii,record,reader,var,data
From: https://www.cnblogs.com/clblacksmith/p/16892383.html

相关文章