About me Héctor Alvarez / @monobotblog / monobot.soft@gmail.com
Reportlab is a PDF generating suite.
It's important to point out that it has an opensource part (where we are focusing) and a privative part that is intended for higher performance and has support included'
Since its a PDF generating tool it has a very nice tutorial in PDF that is generated on the fly.
You can download it from here.
Those instructions are more in depth than this presentation.
A reportlab PDF document is named canvas that can contain a number of pages, the templates and inside them can be rendered a number of items named flowables
The canvas is the space where everything happens, since its a space it has dimension and to be able to place the items it has coordinates.
And since its the main component its where you define the PDF name that will be generated.
from reportlab.pdfgen import canvas
def hello(c):
c.drawString(100, 100, "Hello World")
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
canvas has a lot of different settings that are in cascade applied to the items that are placed in it
setTitle Title of the pdf document.
setFont Sets the font style and font size.
setLineWidth Line width of the lines or draws.
setStrokeColor Color of the lines and texts.
setFillColor If the drawins are closed defines their fill color.
setDash Sets the line dash style.
Its coordinates can be modified and rotated.
translate Translates the coordinate system.
rotate Rotates the coordinate system.
saveState Saves the state of the canvas (position, rotation, colores, strokes, everything), before further changes.
restoreState Restores previously saved state.
The template defines where and how the different flowable can be rendered.
To be able to locate flowables inside a template you have to define on what regions those flowables can be rendered, those regions are named frames
Anything that will be rendered is a flowable, there are many different flowables:
paragraphs
images
tables
graphics
charts
The
It will be impossible to work with all the rest of the things with a good amount of tools like:
fonts
color
dimensions (cms, inchs, A4, letter, etc...)