The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a recurring invoice generator

Creating a recurring invoice generator can be approached in multiple ways depending on the technology stack and environment you want to use. Below is a simplified example of how to create a basic recurring invoice generator using Python. This script will generate invoices on a recurring schedule, such as monthly, and save them as PDF files.


Recurring Invoice Generator (Python Example)

This example will:

  • Define invoice data

  • Generate an invoice PDF

  • Schedule recurring invoice creation (e.g., every month)


python
from fpdf import FPDF import datetime import os import schedule import time class InvoiceGenerator: def __init__(self, client_name, client_address, items, invoice_number, invoice_date): self.client_name = client_name self.client_address = client_address self.items = items # list of tuples (description, quantity, price) self.invoice_number = invoice_number self.invoice_date = invoice_date self.pdf = FPDF() def generate_pdf(self): self.pdf.add_page() self.pdf.set_font("Arial", size=12) # Header self.pdf.cell(200, 10, txt="Invoice", ln=True, align="C") # Invoice Info self.pdf.cell(100, 10, f"Invoice Number: {self.invoice_number}", ln=True) self.pdf.cell(100, 10, f"Invoice Date: {self.invoice_date.strftime('%Y-%m-%d')}", ln=True) # Client Info self.pdf.cell(100, 10, f"Billed To: {self.client_name}", ln=True) self.pdf.multi_cell(0, 10, f"Address: {self.client_address}") self.pdf.ln(10) # Table Header self.pdf.cell(80, 10, "Description", 1) self.pdf.cell(30, 10, "Quantity", 1) self.pdf.cell(40, 10, "Unit Price", 1) self.pdf.cell(40, 10, "Total", 1, ln=True) # Table Rows total_amount = 0 for desc, qty, price in self.items: total = qty * price total_amount += total self.pdf.cell(80, 10, desc, 1) self.pdf.cell(30, 10, str(qty), 1) self.pdf.cell(40, 10, f"${price:.2f}", 1) self.pdf.cell(40, 10, f"${total:.2f}", 1, ln=True) self.pdf.ln(10) self.pdf.cell(150, 10, "Total Amount", 1) self.pdf.cell(40, 10, f"${total_amount:.2f}", 1, ln=True) # Save PDF file_name = f"invoice_{self.invoice_number}.pdf" self.pdf.output(file_name) print(f"Invoice {file_name} generated successfully.") def create_invoice(): today = datetime.date.today() invoice_number = today.strftime("%Y%m") # e.g. 202505 for May 2025 # Example invoice data - in real case, fetch from DB or input client_name = "John Doe" client_address = "123 Main StreetnCityvillenCountry" items = [ ("Website Design", 1, 500.00), ("Hosting (1 year)", 1, 100.00), ("Maintenance", 12, 25.00) ] invoice = InvoiceGenerator(client_name, client_address, items, invoice_number, today) invoice.generate_pdf() # Schedule to run once every month schedule.every(30).days.do(create_invoice) print("Recurring invoice generator started. Waiting to generate invoices...") while True: schedule.run_pending() time.sleep(1)

How This Works

  • The script uses fpdf library to create PDFs.

  • InvoiceGenerator class formats invoice content and saves it as a PDF.

  • The create_invoice function generates a new invoice using preset data and saves it.

  • The script schedules this function to run every 30 days using the schedule module.

  • You can modify the scheduling logic for exact dates or intervals.


Requirements

Install dependencies before running:

bash
pip install fpdf schedule

This is a minimal example and can be expanded with:

  • Dynamic invoice numbers stored in a database

  • Fetching client data and invoice items from external sources

  • Emailing generated invoices automatically

  • More sophisticated scheduling (e.g., monthly on the 1st day)

If you want me to build this for a web framework (like Django, Flask, Node.js) or a specific platform, just let me know!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About