Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,21 @@ def fill_form(self, pdf_form: str, llm: LLM):
for annot in sorted_annots:
if annot.Subtype == "/Widget" and annot.T:
if i < len(answers_list):
annot.V = f"{answers_list[i]}"
annot.AP = None
field_type = annot.FT
value = str(answers_list[i]).strip().lower()

if field_type == "/Btn":
# Handle checkbox and radio button fields
if value in ("yes", "true", "1", "checked"):
import pdfrw
annot.update(pdfrw.PdfDict(V=pdfrw.PdfName("Yes"), AS=pdfrw.PdfName("Yes")))
else:
import pdfrw
annot.update(pdfrw.PdfDict(V=pdfrw.PdfName("Off"), AS=pdfrw.PdfName("Off")))
else:
# Handle normal text fields (original behavior)
annot.V = f"{answers_list[i]}"
annot.AP = None
i += 1
else:
# Stop if we run out of answers
Expand Down
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Union
import os
# from backend import Fill
from commonforms import prepare_form
Expand Down Expand Up @@ -50,7 +51,7 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio

# if __name__ == "__main__":
# file = "./src/inputs/file.pdf"
# 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"
# user_input = open("./src/inputs/input.txt").read().strip()
# fields = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"]
# prepared_pdf = "temp_outfile.pdf"
# prepare_form(file, prepared_pdf)
Expand All @@ -67,7 +68,7 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio

if __name__ == "__main__":
file = "./src/inputs/file.pdf"
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"
user_input = open("./src/inputs/input.txt").read().strip()
fields = ["Employee's name", "Employee's job title", "Employee's department supervisor", "Employee's phone number", "Employee's email", "Signature", "Date"]
prepared_pdf = "temp_outfile.pdf"
prepare_form(file, prepared_pdf)
Expand Down