-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexlinks.py
More file actions
48 lines (27 loc) · 1.14 KB
/
Copy pathindexlinks.py
File metadata and controls
48 lines (27 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pymupdf
print("Index text into internal links in the document")
filename = input("Filename: ")
doc = pymupdf.open(filename)
pgnum = input("Page index: ")
page = doc[int(pgnum)]
gt = page.get_text("dict",sort=True)
for b in gt["blocks"]:
if b["type"] == 0: # text block
for line in b["lines"]:
for span in line["spans"]:
if(len(span['text']) > 3):
print(span['text'],"\n")
mklink = input("\tMake link (y/n): ").strip().lower() == 'y'
if(mklink):
topage = int(input("\tTo page index: "))
print(span['bbox'])
page.insert_link({
"kind": pymupdf.LINK_GOTO,
"from": pymupdf.Rect(span['bbox'][0], span['bbox'][1], span['bbox'][2], span['bbox'][3]),
"page": topage})
print("\tLink created to page", topage, "\n")
print("\n")
output = input("Output filename: ")
if(output.strip()):
doc.save(output)
doc.close()