首页 > 解决方案 > 无法使用 Python 的 pdfrw 库获取可填充框的密钥

问题描述

使用 pdfrw 处理 Python 脚本以提取可填写的 pdf 并自动填写。我有一个电子表格提供给我,我必须用不同的信息多次填写同一张表格。我使用的过程与许多人使用的基本相同,但我无法获得任何键的输出。我尝试了一个完全不编辑我的脚本的不同的 pdf,它吐出了所有的键。好像是pdf的问题。有人有想法么?我觉得第一个想法是确保 pdf 实际上是可填写的,我向你保证是的。我的脚本如下。有效的 pdf 是 1.7 版的 pdf,而无效的是 1.6 版。

#! /usr/bin/python3

import pdfrw


### USER INPUTS ###
inPdfFile = 'inputPdf.pdf'
outPdfFile = 'filledPdf.pdf'
### EXIT USER INPUTS ###
        

### FORM FIELD TYPES ###
annots = '/Annots'
t = '/T'
v = '/V'
#rect = '/Rect'
subtype = '/Subtype'
widget = '/Widget'
#tx = '/Tx'
#ft = '/FT'
### END FORM FIELD TYPES ###


### BEGIN ###
inFile = pdfrw.PdfReader(inPdfFile)

for Page in inFile.pages:
    if Page[annots]:
        for a in Page[annots]:
            if a[t] and a[subtype] == widget:
                key = a[t][1:-1]
                print(key)

标签: pythonpdfpdfrwfillable

解决方案


推荐阅读