"Gadgets" Automatically generate PDF index with JS __js

Source: Internet
Author: User

Get a PDF that doesn't have a catalog because it's really uncomfortable ... So think there is no way to automate the method can be generated directory quq, check it out. Acrobat has JS API can provide, but after writing found only in Acrobat can index Quq, other readers cannot use index ... can only see the directory ... I'm really upset. (* ̄^ ̄)

Let's talk about thinking first. It's silly. In general, when the book is sold in places where there are books and page numbers, this is very easy to find. Then copy into TXT, first use Python to turn it into an array (because lazy so are all level of directory), and then use the JS script to add an array of directories.

Python:

#usr/bin/env python
#-*-coding:utf-8-*-

import Re, sys

Reload (SYS)
sys.setdefaultencoding (' UTF8 ')

filename = "Catagory.txt"
output = "Result.txt"

file = open (filename, "R") Out
= open (Output, "w")

ret = "["
pat = re.compile (. *?) (\d{1,4}$) ') for line in
File.readlines ():
    try:
        tmp =  re.findall (Pat, line)
        print tmp[0][0]  , tmp[0][1]
        ret = "[" + Tmp[0][0].strip () + "'," + tmp[0][1] + "],\n"
    except:
        ret = "[" + Line.strip () + "'],\n"

ret = "]"
out.write (ret)

file.close ()
out.close ()

Is it easy to have ... I think I really use python as a tool ...

Then the JS code, this is the official document directly on some:

function CreateBookMark (parent) {for
	(var i=0;i<arr.length;i++) {
		if (arr[i].length>1)
		Parent.createchild (arr[i].[ 0], "this.pagenum=16+" +arr[i]. [1]); This 16 is the page number in the PDF and the offset of the original page number of the bibliography
		else Parent.createchild (arr[i].[ 0]);
	}
Createchild (name, script). The first is the name of the bookmark, the second is what you do with the bookmark, and then you can set the Pagenum to the target page number.

What I do is white hat, web security ... The general result is this:

But only in Acrobat, with Quq, Boingo hindering.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.