test_pdf.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:ZLib 作者: zenist 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号