pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

Execute button in a pdf form

Open slimbeji-pb opened this issue 6 months ago • 0 comments

Explanation

Hello,

I am exploring how to populate a pdf form using pypdf. The pdf form I am working on is the following one: https://www.uspto.gov/sites/default/files/patents/process/file/efs/guidance/updated_IDS.pdf

It is used for patent applications.

Reading the docs I managed to fill some fields like so:

Code Example

from pypdf import PdfReader, PdfWriter

INPUT = "form.pdf"
OUTPUT = "filled-out.pdf"

reader = PdfReader(INPUT)
writer = PdfWriter()
fields = reader.get_fields() 
# print(list(fields.keys()) # This is just to extract the fields name
writer.append(reader)

form = {
    "us-ids[0].sfpatitemflow[0].patItemsf[0].examinertxt[1]" : "Gary Moore",
    "us-ids[0].sfpatitemflow[0].patItemsf[0].citenotxt[1]": "1",
    "us-ids[0].sfpatitemflow[0].patItemsf[0].patnumbertxt[1]": "12345678",
    "us-ids[0].sfpatitemflow[0].patItemsf[0].kindtxt[1]": "1",
    "us-ids[0].sfpatitemflow[0].patItemsf[0].issdttxt[1]": "2023-12-20",
    "us-ids[0].sfpatitemflow[0].patItemsf[0].patnametxt[1]": "Gibson Les Paul",
    "us-ids[0].sfpatitemflow[0].patItemsf[0].pagescolumnsTxt[1]": "Page 1 Line 1",
}

writer.update_page_form_field_values(
    writer.pages[0], form
)
with open(OUTPUT, "wb") as output_stream:
    writer.write(output_stream)

Request

What I didn't figure out yet is how to execute the "Add" Button so I can add more rows and more fields using pypdf. For example how to "click/execute" the button us-ids[0].sffoot[0].addbtn[0]. How can I generate us-ids[0].sfpatitemflow[0].patItemsf[1] fields ?

slimbeji-pb avatar Dec 24 '23 10:12 slimbeji-pb