如何给PDF加书签

如何给PDF文档加书签(代码实现PDF书签)(转来的)

来源: 吕红亚的日志

把下面的代码保存为一个bookmark_page.js文件

//=================复制下面的代码=====================

// bookmark_page.js, ver. 1.0

// 1 修改为中文标签

// 2 设置书签时可以自动获取当前的书名

// 3 自动获取当前所在的页码与总页数,方便查阅

// 4 实现更多功能可以参看Adobe Reader的SDK

// use this delimiter for serializing our array

var bp_delim= '%#%#';

function SaveData( data ) {

// data is an array of arrays that needs

// to be serialized and stored into a persistent

// global string

var ds= '';

for( ii= 0; ii

for( jj= 0; jj

if( ii!= 0 || jj!= 0 )

ds+= bp_delim;

ds+= data[ii][jj];

}

}

global.pdf_hacks_js_bookmarks= ds;

global.setPersistent( "pdf_hacks_js_bookmarks", true );

}

function GetData() {

// reverse of SaveData; return an array of arrays

if( global.pdf_hacks_js_bookmarks== null ) {

return new Array(0);

}

var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );

var data= new Array();

for( ii= 0; ii

var record= new Array();

for( jj= 0; jj

record.push( flat[ii] );

}

if( record.length== 3 ) {

data.push( record );

}

}

return data;

}

//Get Current Date

function DateNow(){

var d, s ;

d = new Date();

s = d.getFullYear()+"/";

s += (d.getMonth() + 1) + "/";

s += d.getDate() ;

/*

s += d.getHours() + ":";

s += d.getMinutes() + ":";

s += d.getSeconds() ;

*/

return(s);

}

function AddBookmark() {

// query the user for a name, and then combine it with

// the current PDF page to create a record; store this record

var thisfilename=this.documentFileName;

thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));

var numPlugInss=this.pageNum+1;

var currentdate=DateNow();

var label=

app.response( "书签名称,可以修改以便于记忆:",

"书签名称",

"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,

false );

if( label!= null ) {

var record= new Array(3);

record[0]= label;

record[1]= this.path;

record[2]= this.pageNum;

data= GetData();

data.push( record );

SaveData( data );

}

}

function ShowBookmarks() {

// show a pop-up menu; this seems to only work when

// a PDF is alreay in the viewer;

var data= GetData();

var items= '';

for( ii= 0; ii

if( ii!= 0 )

items+= ', ';

items+= '"'+ ii+ ': '+ data[ii][0]+ '"';

}

// assemble the command and the execute it with eval()

var command=

'app.popUpMenu( '+ items+ ' );';

var selection= eval( command );

if( selection== null ) {

return; // exit

}

// the user made a selection; parse out its index and use it

// to access the bookmark record

var index= 0;

// toString() converts the String object to a string literal

// eval() converts the string literal to a number

index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );

if( index

try {

// the document must be 'disclosed' for us to have any access

// to its properties, so we use these FirstPage NextPage calls

//

app.openDoc( data[index][1] );

app.execMenuItem( "FirstPage" );

for( ii= 0; ii

app.execMenuItem( "NextPage" );

}

}

catch( ee ) {

var response=

app.alert("打开书签错误.\n是否删除本书签?", 2, 2,"删除书签");

if( response== 4 && index

data.splice( index, 1 );

SaveData( data );

}

}

}

}

function DropBookmark() {

// modelled after ShowBookmarks()

var data= GetData();

var items= '';

for( ii= 0; ii

if( ii!= 0 )

items+= ', ';

items+= '"'+ ii+ ': '+ data[ii][0]+ '"';

}

var command= 'app.popUpMenu( '+ items+ ' );';

var selection= eval( command );

if( selection== null ) {

return; // exit

}

var index= 0;

index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );

if( index

data.splice( index, 1 );

SaveData( data );

}

}

function ClearBookmarks() {

if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) {

SaveData( new Array(0) );

}

}

app.addMenuItem( {

cName: "-", // menu divider

cParent: "View", // append to the View menu

cExec: "void(0);" } );

app.addMenuItem( {

cName: "设置本页为书签(&B)",

cParent: "View",

cExec: "AddBookmark();",

cEnable: "event.rc= (event.target != null);" } );

app.addMenuItem( {

cName: "转到指定书签(&T)",

cParent: "View",

cExec: "ShowBookmarks();",

cEnable: "event.rc= (event.target != null);" } );

//cEnable: "event.rc= true;" } );

app.addMenuItem( {

cName: "删除一个书签(&D)",

cParent: "View",

cExec: "DropBookmark();",

cEnable: "event.rc= (event.target != null);" } );

app.addMenuItem( {

cName: "清除所有书签(&C)",

cParent: "View",

cExec: "ClearBookmarks();",

cEnable: "event.rc= true;" } );

//==================复制上面的代码=================

5 将文件拷贝到C:\Program Files\Adobe\Reader 9.0\Reader\Javascripts(参考自己的安装目录)目录下

6 重新打开Adobe Reader,看看视图,相信不用说任何东西,大家都会用了

出处(转载请说明):http://semoon1314.blog.

163.com/blog/static/[***********]2643/

如何给PDF文档加书签(代码实现PDF书签)(转来的)

来源: 吕红亚的日志

把下面的代码保存为一个bookmark_page.js文件

//=================复制下面的代码=====================

// bookmark_page.js, ver. 1.0

// 1 修改为中文标签

// 2 设置书签时可以自动获取当前的书名

// 3 自动获取当前所在的页码与总页数,方便查阅

// 4 实现更多功能可以参看Adobe Reader的SDK

// use this delimiter for serializing our array

var bp_delim= '%#%#';

function SaveData( data ) {

// data is an array of arrays that needs

// to be serialized and stored into a persistent

// global string

var ds= '';

for( ii= 0; ii

for( jj= 0; jj

if( ii!= 0 || jj!= 0 )

ds+= bp_delim;

ds+= data[ii][jj];

}

}

global.pdf_hacks_js_bookmarks= ds;

global.setPersistent( "pdf_hacks_js_bookmarks", true );

}

function GetData() {

// reverse of SaveData; return an array of arrays

if( global.pdf_hacks_js_bookmarks== null ) {

return new Array(0);

}

var flat= global.pdf_hacks_js_bookmarks.split( bp_delim );

var data= new Array();

for( ii= 0; ii

var record= new Array();

for( jj= 0; jj

record.push( flat[ii] );

}

if( record.length== 3 ) {

data.push( record );

}

}

return data;

}

//Get Current Date

function DateNow(){

var d, s ;

d = new Date();

s = d.getFullYear()+"/";

s += (d.getMonth() + 1) + "/";

s += d.getDate() ;

/*

s += d.getHours() + ":";

s += d.getMinutes() + ":";

s += d.getSeconds() ;

*/

return(s);

}

function AddBookmark() {

// query the user for a name, and then combine it with

// the current PDF page to create a record; store this record

var thisfilename=this.documentFileName;

thisfilename=thisfilename.substr(0,thisfilename.lastIndexOf("."));

var numPlugInss=this.pageNum+1;

var currentdate=DateNow();

var label=

app.response( "书签名称,可以修改以便于记忆:",

"书签名称",

"《"+thisfilename+"》第 "+numPlugInss+" 页/共 "+this.numPages+" 页 "+currentdate,

false );

if( label!= null ) {

var record= new Array(3);

record[0]= label;

record[1]= this.path;

record[2]= this.pageNum;

data= GetData();

data.push( record );

SaveData( data );

}

}

function ShowBookmarks() {

// show a pop-up menu; this seems to only work when

// a PDF is alreay in the viewer;

var data= GetData();

var items= '';

for( ii= 0; ii

if( ii!= 0 )

items+= ', ';

items+= '"'+ ii+ ': '+ data[ii][0]+ '"';

}

// assemble the command and the execute it with eval()

var command=

'app.popUpMenu( '+ items+ ' );';

var selection= eval( command );

if( selection== null ) {

return; // exit

}

// the user made a selection; parse out its index and use it

// to access the bookmark record

var index= 0;

// toString() converts the String object to a string literal

// eval() converts the string literal to a number

index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );

if( index

try {

// the document must be 'disclosed' for us to have any access

// to its properties, so we use these FirstPage NextPage calls

//

app.openDoc( data[index][1] );

app.execMenuItem( "FirstPage" );

for( ii= 0; ii

app.execMenuItem( "NextPage" );

}

}

catch( ee ) {

var response=

app.alert("打开书签错误.\n是否删除本书签?", 2, 2,"删除书签");

if( response== 4 && index

data.splice( index, 1 );

SaveData( data );

}

}

}

}

function DropBookmark() {

// modelled after ShowBookmarks()

var data= GetData();

var items= '';

for( ii= 0; ii

if( ii!= 0 )

items+= ', ';

items+= '"'+ ii+ ': '+ data[ii][0]+ '"';

}

var command= 'app.popUpMenu( '+ items+ ' );';

var selection= eval( command );

if( selection== null ) {

return; // exit

}

var index= 0;

index= eval( selection.substring( 0, selection.indexOf(':') ).toString() );

if( index

data.splice( index, 1 );

SaveData( data );

}

}

function ClearBookmarks() {

if( app.alert("确认要清除所有的书签吗?", 2, 2,"删除书签" )== 4 ) {

SaveData( new Array(0) );

}

}

app.addMenuItem( {

cName: "-", // menu divider

cParent: "View", // append to the View menu

cExec: "void(0);" } );

app.addMenuItem( {

cName: "设置本页为书签(&B)",

cParent: "View",

cExec: "AddBookmark();",

cEnable: "event.rc= (event.target != null);" } );

app.addMenuItem( {

cName: "转到指定书签(&T)",

cParent: "View",

cExec: "ShowBookmarks();",

cEnable: "event.rc= (event.target != null);" } );

//cEnable: "event.rc= true;" } );

app.addMenuItem( {

cName: "删除一个书签(&D)",

cParent: "View",

cExec: "DropBookmark();",

cEnable: "event.rc= (event.target != null);" } );

app.addMenuItem( {

cName: "清除所有书签(&C)",

cParent: "View",

cExec: "ClearBookmarks();",

cEnable: "event.rc= true;" } );

//==================复制上面的代码=================

5 将文件拷贝到C:\Program Files\Adobe\Reader 9.0\Reader\Javascripts(参考自己的安装目录)目录下

6 重新打开Adobe Reader,看看视图,相信不用说任何东西,大家都会用了

出处(转载请说明):http://semoon1314.blog.

163.com/blog/static/[***********]2643/


相关内容

  • PDF阅读器怎么加书签 带书签的PDF阅读器
  • 百度上一搜索"PDF阅读器",展现给大家的是无数品牌的阅读器.大家究竟听说过哪些?又有多少了解呢?就拿最简单的PDF书签来说吧,哪些PDF阅读器带有书签功能呢?带书签功能的PDF阅读器又是如何使用的呢?下面小编就以其中一例简单说下PDF阅读器的书签功能怎么用! 介绍PDF书签功能 ...

  • 如何制作pdf文档
  • PDF电子书制作 制作第一步:准备好源文件. 源文件可能是文本文件.HTML文件.DOC文件.RTF文件等等.我们这里假设源文件是DOC文件(即MicrosoftWord文档).因为我们是通过打印方式来制作的,所以跟你的电子文档处理软件有一定的关系,因为所有的文字处理和排版都需要在你的文档处理软件中 ...

  • 怎样制作PDF电子文档
  • 怎样制作PDF电子文档本文摘自: 看到网上很多PDF格式的文档,做得非常精美,我需要给单位制作一份电子文档,请问如何制作呢? http://itkeys.cn/ 答:这次给你推荐PDFFactory吧,下载地址上网搜一下,用它可以方便地把Word文档.TXT文档.图片等诸多文件格式转化为PDF文件格 ...

  • [注意]机加工工艺及装备.材料汇总贴(方便大家查找资料)[好域安机械论坛]
  • [注意]机加工工艺及装备.材料汇总贴(方便大家查找资料) 1.机械加工先进工艺窍门与新技术应用图示例解及常用速查手册(998元) http://www.haoyuansz.com/bbs/dispbbs.asp?boardID=26&ID=3058&page=1 2.机械零件结构工艺 ...

  • PDF电子书简要制作方法
  • PDF电子书简要制作方法 本文借助Adobe Acrobat给大家讲解一下PDF电子文档的简单制作方法以及在制作过程中可能出现的问题或者一些需要大家注意的地方,我的测试环境如下: 软件环境:Adobe Acrobat 5 正式版 + 中文简体字体库:中文简体Windows2000 Pro Micro ...

  • 大量品质管理书籍和资料,品管人员必备
  • │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 2010 年质量专业理论与实务(中级)过关必做 1500 题.pdf 21 世纪车间主任工作手册(添加书签).pdf 35 钢显 ...

  • PDF软件清单
  • PDF - 小众软件 PDF工具 - 独木成林 PDF Rotator – 旋转你的 PDF 文档 18 PDF Rotator 是款简单的 PDF 旋转工具,可以轻松的将 PDF 文档进行顺/逆时针 90度.180度旋转,并保存.@Appinn 感谢 dicksonwoo 推荐.为了测试 PDF ...

  • 试验室操作手册
  • 上海同望信息技术有限公司 上海同望信息技术有限公司试验室平台操作使用说明 目录 一.登录.......................................................................................................... ...

  • 10个可以对Firefox内存占用及速度进行优化的方法
  • 目前,Firefox的全球占有率已经超过10%,但也经常听到有人抱怨它占用内存太多,或者速度变慢.Download.com的这篇文章,给了10个可以对Firefox内存占用及速度进行优化的方法. 1. PDF Download. 在Windows下面,Adobe的Reader把自己的插件装得很好,所 ...