设为首页 加入收藏

TOP

Python 生成pdf文件
2014-11-24 03:17:13 来源: 作者: 【 】 浏览:1
Tags:Python 生成 pdf 文件

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 生成pdf文件


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python 发送email 下一篇shell切换用户执行后面语句,su与..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)
·Python超详细一条龙 (2025-12-24 18:49:42)
·【超详细】JDK 下载 (2025-12-24 18:19:32)
·Java_百度百科 (2025-12-24 18:19:29)