def test_08_table(self):
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Spacer, Paragraph, Table
from reportlab.lib.units import inch
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib import fonts, colors
pdfmetrics.registerFont(TTFont('chsFont', 'STHeiti Light.ttc'))
stylesheet = getSampleStyleSheet()
elements = []
doc = SimpleDocTemplate("demo.pdf")
elements.append(Paragraph('<font name="chsFont">AUT OOM????</font>', stylesheet['Title']))
elements.append(Spacer(1,12))
stylesheet.add(ParagraphStyle(name="Justify", alignment=TA_JUSTIFY))
stylesheet['Justify'].contName = 'chsFont'
data = []
data.append(["???","???","???"])
data.append(["120","6","50"])
ts = [('INNERGRID',(0,0),(-1,-1),0.25, colors.black),("BOX",(0,0),(-1,-1),0.25,colors.black),('FONT',(0,0),(-1,-1), 'chsFont')]
table = Table(data, 2.1*inch, 0.24*inch, ts)
elements.append(table)
doc.build(elements)
评论列表
文章目录