【发布时间】:2019-04-23 13:37:18
【问题描述】:
按照Creating Interactive PDF Forms in ReportLab with Python 中的示例,我创建了一个带有一些单选按钮的表单
这是代码示例,尤其是。对于收音机:
simple_radios.py
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfform
from reportlab.lib.colors import magenta, pink, blue, green
def create_simple_radios():
c = canvas.Canvas('simple_radios.pdf')
c.setFont("Courier", 20)
c.drawCentredString(300, 700, 'Radio demo')
c.setFont("Courier", 14)
form = c.acroForm
c.drawString(10, 650, 'Dog:')
form.radio(name='radio1', tooltip='Field radio1',
value='value1', selected=False,
x=110, y=645, buttonStyle='check',
borderStyle='solid', shape='square',
borderColor=magenta, fillColor=pink,
textColor=blue, forceBorder=True)
form.radio(name='radio1', tooltip='Field radio1',
value='value2', selected=True,
x=110, y=645, buttonStyle='check',
borderStyle='solid', shape='square',
borderColor=magenta, fillColor=pink,
textColor=blue, forceBorder=True)
c.drawString(10, 600, 'Cat:')
form.radio(name='radio2', tooltip='Field radio2',
value='value1', selected=True,
x=110, y=595, buttonStyle='cross',
borderStyle='solid', shape='circle',
borderColor=green, fillColor=blue,
borderWidth=2,
textColor=pink, forceBorder=True)
form.radio(name='radio2', tooltip='Field radio2',
value='value2', selected=False,
x=110, y=595, buttonStyle='cross',
borderStyle='solid', shape='circle',
borderColor=green, fillColor=blue,
borderWidth=2,
textColor=pink, forceBorder=True)
c.drawString(10, 550, 'Pony:')
form.radio(name='radio3', tooltip='Field radio3',
value='value1', selected=False,
x=110, y=545, buttonStyle='star',
borderStyle='bevelled', shape='square',
borderColor=blue, fillColor=green,
borderWidth=2,
textColor=magenta, forceBorder=False)
form.radio(name='radio3', tooltip='Field radio3',
value='value2', selected=True,
x=110, y=545, buttonStyle='star',
borderStyle='bevelled', shape='circle',
borderColor=blue, fillColor=green,
borderWidth=2,
textColor=magenta, forceBorder=True)
c.save()
if __name__ == '__main__':
create_simple_radios()
我对该代码的问题/疑问是: 1.) 收音机始终处于“推送”状态。我怎样才能解除它们? 2.) 可以分组,以便根据组只按下一 (1) 个单选按钮 3.)我以后如何以编程方式读取按钮的状态,例如通过 PyPDF2?
版本:
Python:3.7.3
报告实验室:3.5.19
枕头:6.0.0
PyPDF2:1.26.0
操作系统:
Windows10 v1809
【问题讨论】: