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 adlines()
return adlines()
def create_pdf(input, output="disk_report.pdf"):
now = day()
date = now.strftime("%h %d %Y %H:%M:%S")
c = canvas.Canvas(output)
textobject = c.beginText()
textobject.setTextOrigin(inch, 11*inch)
for line in input:
c.drawText(textobject)
c.showPage()
c.save()
report = disk_report()
create_pdf(report)
感兴趣的读者可以调试运⾏⼀下,对不⾜之处加以改进,以实现功能的最佳应⽤!javascript淘宝购物车代码

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。