我正在做一个python3.4项目,它使用fdfgen和pdftk来填写pdf。我可以很容易地填充文本字段。我搞不懂如何勾选一个方框。在
下面是我的python脚本的一部分:
fields = generate_vs300_field_list(answers_dict) # Returns list of tuples of fields and text to be added to pdf
fdf = forge_fdf("", fields, [], [], [])
logging.debug('Called forge_fdf function. About to open fdf_file.')
fdf_file = open(os.path.join(destination_dir, 'vs300.fdf'), 'wb')
logging.debug('Opened fdf_file. About to write to it.')
fdf_file.write(fdf)
fdf_file.close()
logging.debug('Wrote to fdf_file and closed it.')
cmd = 'pdftk "{0}" fill_form "{1}" output "{2}" dont_ask'.format(
'./styles/vs300.pdf',
os.path.join(destination_dir, 'vs300.fdf'),
os.path.join(destination_dir, 'vs300.pdf')
)
logging.debug('About to send this command to pdftk: ' + cmd)
os.system(cmd)
logging.debug('Command sent. Removing temporary fdf file.')
os.remove(os.path.join(destination_dir, 'vs300.fdf'))
我可以成功地创建一个元组列表,将元组中的第一项作为字段名,第二项是我要添加的字段的文本。在
我想不出怎么做的是勾选一个方框。如果我在pdf上运行pdftk dump_data_字段,下面是我要检查的复选框的条目:
^{pr2}$我不知道如何a)更改fdf文件以使复选框显示为已选中;b)如何使用fdfgen进行更改。在
通过fdfgen的复选框字段将遍历fdf_data_names变量,而不是fdf_data_字符串。您还应该检查PDF本身,看看复选框对其“on”触发器使用了什么。在
你打电话给forge他看起来像:
相关问题 更多 >
编程相关推荐