python reportlab 生成中文PDF范例,pythonreportlab,df -h 命令内容生成
python reportlab 生成中文PDF范例,pythonreportlab,df -h 命令内容生成
df -h 命令内容生成PDF
#!/usr/bin/python#coding=gbkimport datetimeimport subprocessimport codecsimport reportlab.pdfbase.ttfontsreportlab.pdfbase.pdfmetrics.registerFont(reportlab.pdfbase.ttfonts.TTFont('song', '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc'))import reportlab.lib.fontsfrom reportlab.pdfgen import canvasfrom reportlab.lib.units import inchdef disk_report(): p = subprocess.Popen("df -h ",shell=True,stdout=subprocess.PIPE) return p.stdout.readlines()def create_pdf(input,output="disk.pdf"): now = datetime.datetime.today() date = now.strftime("%h %d %Y %H:%M:%S") c = canvas.Canvas(output) c.setFont('song',10) textobject = c.beginText() textobject.setTextOrigin(inch,11*inch) textobject.textLines('''Disk Capacity Report: %s ''' % date ) for line in input: line=line.decode("gbk") textobject.textLine(line.strip()) c.drawText(textobject) c.showPage() c.save()report = disk_report()create_pdf(report)
相关内容
- 实现移位密码(凯撒密码)加密算法(两种方法),凯
- python glob 用通配符查找指定目录中的文件,,[Python]代码
- 使用python smtplib库发邮件添加cc,bcc,smtplibbcc,[Python]代
- Python分割文件,python分割,[Python]代码#e
- 自动登录网络设备备份配置文件 version0.2版本,自动登
- 学习和分享,学习分享,[Python]代码#-
- Python 函数的周期性执行,python函数周期性,python sched
- 基于PyQt的Python识别Access密码,pyqtpythonaccess,[Python]代码
- 用来调试嵌入式服务器连接数,写的简单python脚本,嵌
- 利用Flask实现在线Whois 域名查询,flaskwhois,[Python]代码
评论关闭