国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python生成pdf文件的方法

2020-02-23 05:37:09
字體:
來源:轉載
供稿:網友

本文實例演示了Python生成pdf文件的方法,是比較實用的功能,主要包含2個文件。具體實現方法如下:

pdf.py文件如下:

#!/usr/bin/pythonfrom reportlab.pdfgen import canvasdef hello():    c = canvas.Canvas("helloworld.pdf")    c.drawString(100,100,"Hello,World")    c.showPage()    c.save()hello()

diskreport.py文件如下:

#!/usr/bin/env pythonimport subprocessimport datetimefrom reportlab.pdfgen import canvasfrom reportlab.lib.units import inchdef 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)

感興趣的讀者可以調試運行一下,對不足之處加以改進,以實現功能的最佳應用!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武功县| 沁阳市| 鹿邑县| 芮城县| 南岸区| 桐乡市| 从江县| 三河市| 新闻| 北票市| 兴宁市| 隆安县| 田阳县| 邵阳市| 三明市| 交城县| 海原县| 汉川市| 仙游县| 库车县| 周宁县| 察雅县| 固镇县| 石台县| 长寿区| 平武县| 腾冲县| 清水河县| 西充县| 项城市| 朝阳县| 兴仁县| 修文县| 常宁市| 斗六市| 西华县| 商丘市| 平乐县| 西华县| 永定县| 岳普湖县|