lundi 28 septembre 2020

Checking a checkbox by passing a value in a dict to fill_form in pypdftk

As the title says, I am passing a dict through fill_form with the pypdftk lib and am trying to check a checkbox with a value. I have tried to change the export value of the checkbox to see if that could affect it, but it hasn't. It seems the checkbox disappears when I pass an unaccepted value to it. I have changed the export value to 'Y'.

import pypdftk
import tkinter as tk
from tkinter.filedialog import asksaveasfilename

headers = ['1','2','3','4','checkbox']
values = ['a','b','c','d','Y']
short_dict = dict(zip(headers,y))
fName = r'file_name'
generated_pdf = pypdftk.fill_form(r'pdf_path',short_dict, asksaveasfilename(defaultextension=".pdf", initialdir="C:\\Desktop", filetypes=[('pdf file', '*.pdf')], initialfile=fName))

I'm still new to Python, so this is my attempt at an MCVE. Hopefully, all the data is there as I cannot share the full script or the pdf since they contain sensitive information.

I have tried to change the export value to different things, as I mentioned, none of which have worked. I have also tried 0/1, on/off, true/false and Yes/No, none of which worked.

Is there a way to pass a value through a dict into a pypdftk.fill_form() call and switch the checkboxes on?




Aucun commentaire:

Enregistrer un commentaire