This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_script.py
55 lines (44 loc) · 1.53 KB
/
example_script.py
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
"""
Demo for pdfformfields.
For more details, go to https://github.com/Balonger/pdfformfields
"""
from pdfformfields import fill_form_fields, generate_dictionary
# Example pdf containing two fields with the ids: first_name, last_name
example_input_pdf = "example_input.pdf"
# Use generate_dictionary() with verbose=True to understand the structure. FieldName is the id of the field.
generate_dictionary(example_input_pdf, verbose=True)
""" The output should be:
rename_me = {
# ---
# FieldType: Text
# FieldName: first_name
# FieldFlags: 0
# FieldValue:
# FieldJustification: Left
# ---
# FieldType: Text
# FieldName: last_name
# FieldFlags: 0
# FieldValue:
# FieldJustification: Left
}
"""
# Use generate_dictionary() without verbose=True to generate a copiable code for the field dictionary onto the console
# generate_dictionary(example_input_pdf)
""" The output should be:
rename_me = {
"first_name": ,
"last_name": ,
}
"""
# Paste code, rename dictionary, and fill in the values however you like
form_field_dictionary = {
"first_name": "John",
"last_name": "Doe",
}
# Output filled in dictionary with the fill_form_fields() function
example_output_pdf = r"example_output.pdf"
fill_form_fields(example_input_pdf, form_field_dictionary, example_output_pdf)
# If you don't want the output to be editable set flatten=True
example_output_pdf_flattened = r"example_output_pdf_flattened.pdf"
fill_form_fields(example_input_pdf, form_field_dictionary, example_output_pdf_flattened, flatten=True)