Python平台的优秀PDF报表类库Reportlab。它不属于Python的标准类库,所以必须手动下载类库包并安装:
yum install python-reportlab -y
这篇文章将介绍reportlab中基本常用的api,使用canvas画出一份整洁的PDF报表。详细内容参考reportlab的官方user guide。
示例一、生成一段文字#!/usr/bin/python
from reportlab.pdfgen import canvas
def hello():
c = canvas.Canvas("helloworld.pdf")
c.drawString(100,100,"Hello,World")
c.showPage()
c.save()
hello()
示例二、生成单个文件的pdf#需要安装字体 yum install wqy-* -y
#!/usr/bin/python
import datetime
import subprocess
import codecs
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
from reportlab.lib.pagesizes import A4, landscape
import reportlab.pdfbase.ttfonts
reportlab.pdfbase.pdfmetrics.registerFont(reportlab.pdfbase.ttfonts.TTFont('song', '/usr/share/fonts/cn/msjh.ttf'))
import reportlab.lib.fonts
def disk