用户:活泼的编程猫Lcp8查看:0 回复:0 评论:0 创建时间:2020-06-13T10:49:13
代码:
from reportlab.pdfgen import canvas from reportlab.pdfbase.ttfonts import TTFont from reportlab.pdfbase.pdfmetrics import registerFont from reportlab.lib import colors import webbrowser from os import path registerFont(TTFont('yaheibt', 'msyhbd.ttc')) registerFont(TTFont('yaheizw', 'msyh.ttc')) c = canvas.Canvas("form.pdf") c.setFont('yaheibt', 32) c.drawCentredString(298, 800, '可修改学生证') form = c.acroForm c.setFont('yaheizw', 16) c.drawCentredString(200, 700, '姓名') form.textfield(x=300, y=680, fillColor=colors.white) c.drawCentredString(200, 600, "性别") c.drawCentredString(300, 600, "男") c.drawCentredString(400, 600, "女") form.checkbox(x=320, y=595, buttonStyle='check') form.checkbox(x=420, y=595, buttonStyle='check') c.drawCentredString(200, 500, "年龄") form.choice(x=300, y=480, value='12', options=[ '{}'.format(str(i))for i inrange(1,19)]) c.drawCentredString(200, 400, "班级") form.choice(x=300, y=380, value='C1901', options=['C190{}'.format(str(i)) for i in range(1, 10)]) c.drawCentredString(200, 300, '学号') form.textfield(x=300, y=280, fillColor=colors.white) c.save() webbrowser.open("file://"+path.realpath("form.pdf"))