Sometime you need to make some pdf looking more professional. In python you use the ReportLab1 package for make Pdf.
Fist the main core
For every document type I need I write a class with a get_pdf for print2 a Pdf.
Here an example3
The real important things are the footer and header function (in our case staticmethod). In each one we add a img (the footer or header) with all the logos and company info in it. If you want you can put the info as text yourself. Remember to save and restore alwayse the canvas because sometime, if you don’t do it can launch error.
The specific printer (or how to use the main core)
After you have done you need to make a “printer” for your document. In this case is a booring paper about Privacy.
This class extend the previus one and fill the buffer with al the relevant info and other element of the document (like titles, paragraphs, tables and images).
For the way I set up this class you have all the page with the letterhead template. This is happening because I setup the onFirstPage which will be call on the first page and the onLaterPages which will be call from page two with the call for the header and the footer function.
I use print for the action of making a Pdf from some data (like a json, a csv or a datasource of other type) If one ore more of this Pdf’s types have a common layout (like a letterhead) I make an parent object for the type of document and call it SomethingPrinter. ↩︎
My default paper is A4 but you can import any format from reportlab.lib.pagesizes or define a new one following this format A4 = (210mm,297mm) ↩︎