File size: 502 Bytes
197a58a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from reportlab.lib.pagesizes import A5
from reportlab.pdfgen import canvas

def create_receipt(text, file_name):
    pdf = canvas.Canvas(file_name, pagesize=A5)
    width, height = A5

    pdf.setFont("Helvetica-Bold", 16)
    pdf.drawCentredString(width / 2, height - 50, "Receipt Summary")

    pdf.setFont("Helvetica", 12)
    text_object = pdf.beginText(50, height - 100)

    for line in text.split("\n"):
        text_object.textLine(line.strip())

    pdf.drawText(text_object)

    pdf.save()