|
1 | 1 | import os |
2 | 2 | from backend import Fill |
| 3 | +from commonforms import prepare_form |
| 4 | +from pypdf import PdfReader |
| 5 | + |
| 6 | +def input_fields(num_fields: int): |
| 7 | + fields = [] |
| 8 | + for i in range(num_fields): |
| 9 | + field = input(f"Enter description for field {i + 1}: ") |
| 10 | + fields.append(field) |
| 11 | + return fields |
3 | 12 |
|
4 | 13 | def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: str): |
5 | 14 | """ |
@@ -36,7 +45,21 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: str) |
36 | 45 |
|
37 | 46 |
|
38 | 47 | if __name__ == "__main__": |
39 | | - file = "/home/juan/Documents/california/UCSC/rte2025/src/inputs/file.pdf" |
40 | | - input = "Hi. The employee's name is John Doe. His job title is managing director. His department supervisor is Jane Doe. His phone number is 123456. His email is jdoe@ucsc.edu. The signature is <Mamañema>, and the date is 01/02/2005" |
| 48 | + file = "[ENTER_DIR_HERE]/FireForm/src/inputs/file.pdf" |
| 49 | + user_input = "Hi. The employee's name is John Doe. His job title is managing director. His department supervisor is Jane Doe. His phone number is 123456. His email is jdoe@ucsc.edu. The signature is <Mamañema>, and the date is 01/02/2005" |
41 | 50 | descriptions = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"] |
42 | | - run_pdf_fill_process(input, descriptions, file) |
| 51 | + prepared_pdf = "temp_outfile.pdf" |
| 52 | + prepare_form(file,prepared_pdf) |
| 53 | + |
| 54 | + reader = PdfReader(prepared_pdf) |
| 55 | + fields = reader.get_fields() |
| 56 | + if(fields): |
| 57 | + num_fields = len(fields) |
| 58 | + else: |
| 59 | + num_fields = 0 |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + #descriptions = input_fields(num_fields) # Uncomment to edit fields |
| 64 | + |
| 65 | + run_pdf_fill_process(user_input, descriptions, file) |
0 commit comments