用户:014965麦芽糖69410查看:1 回复:1 评论:1 创建时间:2021-11-05T19:36:46
from reportlab.graphics.charts.legends import Legend
from reportlab.lib.colors import*
from reportlab.graphics import renderPDF
from reportlab.graphics.barcode import qr
from PIL import Image
from reportlab.graphics.shapes import Drawing
from reportlab.pdfbase.pdfmetrics import registerFont
from reportlab.graphics.charts.piecharts import Pie
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas as cva
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
import sys
import os
def pdf(name, lenpage=1, data=None, ttfont=('fangzheng.TTF', 36), pagesize=(800, 700), is_show=True):
registerFont(TTFont('ymzjt', ttfont[0]))
c = cva.Canvas(name)
c.setFont('ymzjt',12)
c.drawCentredString(290,800,'the letter to coding world')
c.drawString(200,700,'姓名')
form = c.acroForm
form.textfield(x=300,y=690, fillColor = white)
c.drawString(200,600,'性别')
c.drawString(300,600,'男')
c.drawString(400,600,'女')
form.checkbox(x=320,y=595,buttonStyle='check')
form.checkbox(x=420,y=595,buttonStyle='check')
c.drawString(200,500,'年龄')
form.choice(x=300,y=480, options=[str(i) for i in range(5,19)], value='10')
c.drawString(200,400,'寄语')
form.textfield(x=300, y=220, width = 220, height = 200, fillColor=white)
# style = getSampleStyleSheet()
# style.add(ParagraphStyle(name = 'cn', fontName = 'ymzjt'))
# img = Image.open('讲义_裁剪后.png')
# c = SimpleDocTemplate(name)
c.save()
if is_show:
os.system(name)
pdf('xlsx.pdf')