DEV Community

IA Printables
IA Printables

Posted on

Generate printable PDF trackers with 20 lines of Python

I wanted a set of simple printable trackers (income, invoices, subscriptions, debt) without paying for a template pack. So I generated them with Python. The whole thing is about 20 lines and gives you clean A4 PDFs you can print.

The idea

Every tracker is the same shape: a coloured header, a title, a row of column names and a grid of empty rows. If you write one function for that, each new tracker is one line.

The code

from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.lib.colors import HexColor

W, H = A4

def make(fn, title, sub, cols, rows=26):
    c = canvas.Canvas(fn, pagesize=A4)
    for _ in range(2):  # two pages
        c.setFillColor(HexColor('#1f3a5f'))
        c.rect(0, H - 90, W, 90, fill=1, stroke=0)
        c.setFillColor(HexColor('#ffffff'))
        c.setFont('Helvetica-Bold', 24)
        c.drawString(40, H - 50, title)
        c.setFont('Helvetica', 11)
        c.drawString(40, H - 72, sub)
        cw = (W - 80) / len(cols)
        y = H - 120
        c.setFillColor(HexColor('#1f3a5f'))
        c.setFont('Helvetica-Bold', 10)
        for i, t in enumerate(cols):
            c.drawString(40 + i * cw + 4, y + 3, t)
        c.setStrokeColor(HexColor('#b8c4d4'))
        for r in range(rows):
            yy = y - 4 - (r + 1) * 26
            c.line(40, yy, W - 40, yy)
            for i in range(1, len(cols)):
                c.line(40 + i * cw, yy, 40 + i * cw, yy + 26)
        c.showPage()
    c.save()

make('invoice-log.pdf', 'Invoice Log', 'Track sent, due and paid invoices',
     ['Invoice #', 'Client', 'Issued', 'Due', 'Amount', 'Status'])
Enter fullscreen mode Exit fullscreen mode

Run it, open the PDF, print. Change the column list and you have a debt tracker, a subscription tracker or a job application tracker.

What I learned

  • Keep the grid lines light grey. Dark lines make a printed sheet look busy.
  • Two pages of 26 rows is enough for a month of most trackers.
  • Render page one to PNG (pdftoppm -r 130 -png) and you get a cover image for free.

Skip the code

If you would rather not run anything, I put the finished PDFs in a small store. They cost $3 each: Invoice Log, Freelancer Income Tracker, Subscription Tracker, Debt Payoff Tracker and Job Application Tracker.

Made with Python and reportlab. The trackers were designed and generated with the help of an AI assistant.

Top comments (0)