Menu

1 / 2

Python Invoice Generator: Create Professional PDFs from CSV in Seconds

DEV Community·Brad·6 months ago
#hzzr1yPH
#python#automation#pdf#business#inch
Reading 0:00
15s threshold

Python Invoice Generator: Create Professional PDFs from CSV in Seconds

Creating invoices manually takes 15-30 minutes each. Python generates professional PDFs in seconds.

Install

pip install reportlab

Enter fullscreen mode

Exit fullscreen mode

Complete Invoice Generator

from reportlab.lib import colors from reportlab.lib.pagesizes import letter from reportlab.platypus import SimpleDocTemplate , Table , TableStyle , Paragraph , Spacer from reportlab.lib.styles import getSampleStyleSheet from reportlab.lib.units import inch from datetime import datetime , timedelta

def generate_invoice ( client_data , line_items , output_file ): doc = SimpleDocTemplate ( output_file , pagesize = letter ) styles = getSampleStyleSheet () story = []

# Header story . append ( Paragraph ( ' INVOICE ' , styles [ ' Title ' ])) story . append ( Spacer ( 1 , 0.2 * inch ))

# Metadata invoice_num = f " INV- { datetime . now (). strftime ( ' %Y%m%d ' ) } - { client_data . get ( ' id ' , ' 001 ' ) } " due_date = ( datetime .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.