-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinvoice_generator.py
64 lines (57 loc) · 1.88 KB
/
invoice_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import csv
from reportlab.lib.pagesizes import letter
from reportlab.lib import colors
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
# Create a PDF document
pdf = SimpleDocTemplate(
"professional_invoice.pdf", pagesize=letter
)
# Read data from CSV
data = []
with open('invoice_data.csv', 'r') as csvfile:
csvreader = csv.reader(csvfile)
for row in csvreader:
data.append(row)
# Table style with more customization
# style = TableStyle([
# ('BACKGROUND', (0, 0), (-1, 0), colors.blue),
# ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
# ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
# ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
# ('FONTSIZE', (0, 0), (-1, 0), 14),
# ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
# ('BACKGROUND', (0, 1), (-1, -1), colors.beige),
# ('GRID', (0, 0), (-1, -1), 1, colors.black)
# ])
style = TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.darkgrey),
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
('FONTSIZE', (0, 0), (-1, 0), 14),
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
('BACKGROUND', (0, 1), (-1, -1), colors.lightgrey),
('GRID', (0, 0), (-1, -1), 1, colors.black)
])
# Create table
table = Table(data)
table.setStyle(style)
# Add table to elements to build
elements = []
styles = getSampleStyleSheet()
custom_style = ParagraphStyle(
name='CustomTitle',
parent=styles['Heading1'],
fontName='Helvetica-Bold',
fontSize=24,
textColor=colors.blue,
alignment=1,
)
title = Paragraph("Professional Invoice", custom_style)
elements.append(title)
elements.append(Spacer(1, 0.5 * inch))
elements.append(table)
# Generate PDF
pdf.build(elements)