A library for generating PDF in Python.
ReportLab is an open source Python library that generates PDFs. It offers two main tools for creating PDFs: direct drawing to a PDF canvas and Platypus, an object-oriented document building framework (All can be combined). Unlike its commercial variant (ReportLab Plus) ReportLab does not support the use of rml to generate PDFs.
This is a basic example of usage:
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch
c = canvas.Canvas("hello.pdf")
c.translate(inch,inch) # move the origin up and to the left
c.setFont("Helvetica", 80) # define a large font
c.setStrokeColorRGB(0.2,0.5,0.3) # choose some colors
c.setFillColorRGB(1,0,1)
c.rect(inch,inch,6*inch,9*inch, fill=1) # draw a rectangle
c.rotate(90) # make text go straight up
c.setFillColorRGB(0,0,0.77) # change color
# say hello (note after rotate the y coord needs to be negative!)
c.drawString(3*inch, -3*inch, "Hello World")
c.showPage()
c.save()
The primary support documents for ReportLab are the ReportLab PDF Library User Guide and the ReportLab PDF API Reference.