diff --git a/src/filler.py b/src/filler.py index e31e535..18206a3 100644 --- a/src/filler.py +++ b/src/filler.py @@ -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 diff --git a/src/main.py b/src/main.py index 5bb632b..56f81ed 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,4 @@ +from typing import Union import os # from backend import Fill from commonforms import prepare_form @@ -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 , 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) @@ -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 , 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)