-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfillform.py
More file actions
88 lines (46 loc) · 1.77 KB
/
Copy pathfillform.py
File metadata and controls
88 lines (46 loc) · 1.77 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pymupdf
print("Fill Form\n")
filename = input("Filename: ")
doc = pymupdf.open(filename)
# Iterate through each page
for page_num in range(len(doc)):
page = doc[page_num]
print(f"Page {page_num + 1}:")
# Get all widgets (form fields) on the page
widgets = page.widgets()
if not widgets:
print(" No form fields found on this page.")
continue
# Iterate through each widget and extract data
for widget in widgets:
field_name = widget.field_name
field_value = widget.field_value
field_type = widget.field_type_string
print(f" Field Name: {field_name}")
print(f" Field Value: {field_value}")
print(f" Field Type: {field_type}\n")
if(field_type == "Text"):
print("Fill field")
field_input = input("Field data: ")
widget.field_value = field_input
widget.update()
elif(field_type == "ListBox"):
print(widget.choice_values)
print("\n")
field_input = int(input(f"New value: (0-{len(widget.choice_values)-1}) "))
widget.field_value = widget.choice_values[field_input]
widget.update()
print("New field value: ",widget.field_value)
elif(field_type == "CheckBox"):
print("Fill field")
#field_input = input("New value (On/Off): ")
field_input = bool(input("New value (True/False): "))
widget.field_value = field_input
widget.update()
flq = input("Flatten form? (y/n): ")
if(flq.strip().lower() == "y"):
print("Flattening...")
doc.bake()
exported = input("Exported file: ")
doc.save(exported,deflate=True,incremental=False,clean=True)
doc.close()