前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 创建PDF文件

python 创建PDF文件

作者头像
py3study
发布2020-01-08 16:20:08
1.6K0
发布2020-01-08 16:20:08
举报
文章被收录于专栏:python3python3

1.安装reportlab库

http://www.reportlab.com/ftp/

ubuntu可以直接 apt-get install python-reportlab

2.实验

代码语言:javascript
复制
>>> from reportlab.pdfgen import canvas >>> def hello():     c = canvas.Canvas("hello World.pdf")  //指定pdf目录和文件名     c.drawString(100,100,"helo World")    //输出区域及内容     c.showPage()     c.save()                                                //保存 

综合案例

代码语言:javascript
复制
>>> import datetime,subprocess >>> from reportlab.pdfgen import canvas >>> from reportlab.lib.units import inch >>>  >>> def dir_report():     p = subprocess.Popen("dir",shell=True,stdout=subprocess.PIPE)     return p.stdout.readlines()  >>> def create_pdf(input,output="dir_report.pdf"):     now = datetime.datetime.today()     date = now.strftime("%h %d %Y %H:%M:%S")     c = canvas.Canvas(output)     textobj = c.beginText()     textobj.setTextOrigin(inch,11*inch)     textobj.textLines('''''         This history sub dir and file is         time is %s''' % date)     for line in input:         textobj.textLine(line.strip())     c.drawText(textobj)     c.showPage()     c.save()       >>> report = dir_report() >>> create_pdf() 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档