This example demonstrates Python's method of producing PDF files, which is a more practical function, consisting mainly of 2 files. The implementation methods are as follows:
pdf.py files are as follows:
#!/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 files are as follows:
#!/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:%s '%date) for line in
input:
textobject.textline (Line.strip ())
C.drawtext (textobject)
c.showpage () c.save () () ())
disk_report () ( )
Interested readers can debug and run, to improve the deficiencies to achieve the best use of functionality!