利用JavaScript自动生PDF书签目录
使用软件版本 Acrobat XI
大多数的扫描版PDF电子图书都可以在官网或者各大网上书店找到目录,很多都是带有页码的。 通过脚本可以将目录自动转化为书签,添加到PDF中。
把目录数据复制粘贴到一个文本文件中,确保每一行都是一条书签,然后合并成一行内容,并将所有换行符用 "\n" 字符替换作为 JavaScript 的转义字符,放入 Bookmark.js 的 data 变量中。
然后把Bookmark.js文件保存到Acrobat安装目录下的JavaScript文件夹里面,并保存 js 为UTF-8的编码。默认位置是:
Adobe\Acrobat 11.0\Acrobat\Javascripts
以 Handbook of Apply Cryptography 这本书的电子版本为例,目录和所有共享章节都可以到网站上下载:
http://cacr.uwaterloo.ca/hac/index.html
此教材目录标签已经处理好上传致下载中心,搜索下载却可,也可以用它做测试用。
Handbook.of.Applied.Cryptography(Alfred.J..Menezes).pdf
操作过程
将 toc3.pdf 的目录内容整理成以下的形式,确保页码数值后没有空格等等,使用 Editplus 的编辑菜单的格式化工具,可以清除行尾的空格:
1 Overview of Cryptography 1
1.1 Introduction 1
1.2 Information security and cryptography 2
……
然后使用 Editplus 这种带有正则替换功能的编辑器,在查找内容和替换内容分别设置为 \n 和 \\n,打开正则功能,将所有换行符替换成 "\n",结果像以下这样。
1 Overview of Cryptography 1 \n1.1 Introduction 1 \n1.2 Information security and cryptography 2 \n
再将这些数据放到 Bookmark.js 的 data 变量中就可以使用了。
完整代码 bookmarks.js:
app.addMenuItem({
cName: "JIMBO:GENERATE",
cUser: "书签自动生成(&B)",
cParent: "Edit",
cExec: "bookm();",
cEnable: "event.rc= (event.target != null);"
});
var rex = /^(.+?)(\d+)$/;
var rel = /\./g;
var bm = {
title : "Handbook of Applied Cryptography",
data : "1 Overview of Cryptography 1\n1.1 Introduction 1\n1.2 Information security and cryptography 2\n1.3 Background on functions 6\n1.3.1 Functions (1-1, one-way, trapdoor one-way) 6\n1.3.2 Permutations 10\n1.3.3 Involutions 10\n1.4 Basic terminology and concepts 11\n1.5 Symmetric-key encryption 15\n1.5.1 Overview of block ciphers and stream ciphers 15\n1.5.2 Substitution ciphers and transposition ciphers 17\n1.5.3 Composition of ciphers 19\n1.5.4 Stream ciphers 20\n1.5.5 The key space 21\n1.6 Digital signatures 22\n1.7 Authentication and identi.cation 24\n1.7.1 Identi.cation 24\n1.7.2 Data origin authentication 25\n1.8 Public-key cryptography 25\n1.8.1 Public-key encryption 25\n1.8.2 The necessity of authentication in public-key systems 27\n1.8.3 Digital signatures from reversible public-key encryption 28\n1.8.4 Symmetric-key vs. public-key cryptography 31\n1.9 Hash functions 33\n1.10 Protocols and mechanisms 33\n1.11 Key establishment, management, and certi.cation 35\n1.11.1 Key management through symmetric-key techniques 36\n1.11.2 Key management through public-key techniques 37\n1.11.3 Trusted third parties and public-key certi.cates 39\n1.12 Pseudorandom numbers and sequences 39\n1.13 Classes of attacks and security models 41\n1.13.1 Attacks on encryption schemes 41\n1.13.2 Attacks on protocols 42\n1.13.3 Models for evaluating security 42\n1.13.4 Perspective for computational security 44\n1.14 Notes and further references 45\n2 Mathematical Background 49\n2.1 Probability theory 50\n2.1.1 Basic definitions 50\n2.1.2 Conditional probability 51\n2.1.3 Random variables 51\n2.1.4 Binomial distribution 52\n2.1.5 Birthday attacks 53\n2.1.6 Random mappings 54\n2.2 Information theory 56\n2.2.1 Entropy 56\n2.2.2 Mutual information 57\n2.3 Complexity theory 57\n2.3.1 Basic definitions 57\n2.3.2 Asymptotic notation 58\n2.3.3 Complexity classes 59\n2.3.4 Randomized algorithms 62\n2.4 Number theory 63\n2.4.1 The integers 63\n2.4.2 Algorithms in Z66\n2.4.3 The integers modulo n 67\n2.4.4 Algorithms in Zn71\n2.4.5 The Legendre and Jacobi symbols 72\n2.4.6 Blum integers 74\n2.5 Abstract algebra 75\n2.5.1 Groups 75\n2.5.2 Rings 76\n2.5.3 Fields 77\n2.5.4 Polynomial rings 78\n2.5.5 Vector spaces 79\n2.6 Finite fields 80\n2.6.1 Basic properties 80\n2.6.2 The Euclidean algorithm for polynomials 81\n2.6.3 Arithmetic of polynomials 83\n2.7 Notes and further references 85\n3 Number-Theoretic Reference Problems 87\n3.1 Introduc