Python生成pdf文件的方法,
Python生成pdf文件的方法,
本文实例演示了Python生成pdf文件的方法,是比较实用的功能,主要包含2个文件。具体实现方法如下:
pdf.py文件如下:
#!/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()
diskreport.py文件如下:
#!/usr/bin/env python import subprocess import datetime from reportlab.pdfgen import canvas from reportlab.lib.units import inch def disk_report(): p = subprocess.Popen("df -h", shell=True, stdout=subprocess.PIPE) # print p.stdout.readlines() return p.stdout.readlines() def create_pdf(input, output="disk_report.pdf"): now = datetime.datetime.today() date = now.strftime("%h %d %Y %H:%M:%S") c = canvas.Canvas(output) textobject = c.beginText() textobject.setTextOrigin(inch, 11*inch) textobject.textLines('''Disk Capcity Report: %s''' %date) for line in input: textobject.textLine(line.strip()) c.drawText(textobject) c.showPage() c.save() report = disk_report() create_pdf(report)
感兴趣的读者可以调试运行一下,对不足之处加以改进,以实现功能的最佳应用!
相关内容
- 基于Python实现的扫雷游戏实例代码,python扫雷
- Python代码的打包与发布详解,python代码详解
- Python使用PyGreSQL操作PostgreSQL数据库教程,pygresqlpostgre
- python新手经常遇到的17个错误分析,python新手遇到17
- Python中apply函数的用法实例教程,pythonapply
- Python中zip()函数用法实例教程,python实例教程
- python处理文本文件实现生成指定格式文件的方法,
- Python中关键字is与==的区别简述,python简述
- 用python删除java文件头上版权信息的方法,pythonjava
- python脚本实现查找webshell的方法,pythonwebshell
评论关闭