└── Main /Main: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from reportlab.pdfgen import canvas 3 | 4 | def generate_invoice(order_id, customer_name, items, total_amount): 5 | filename = f"invoice_{order_id}.pdf" 6 | pdf = canvas.Canvas(filename) 7 | 8 | pdf.setFont("Helvetica-Bold", 16) 9 | pdf.drawString(200, 800, f"Invoice #{order_id}") 10 | 11 | pdf.setFont("Helvetica", 12) 12 | pdf.drawString(100, 770, f"Customer: {customer_name}") 13 | pdf.drawString(100, 750, "Items:") 14 | 15 | y = 730 16 | for item, price in items: 17 | pdf.drawString(120, y, f"{item} - ${price}") 18 | y -= 20 19 | 20 | pdf.setFont("Helvetica-Bold", 12) 21 | pdf.drawString(100, y - 20, f"Total: ${total_amount}") 22 | 23 | pdf.save() 24 | print(f"Invoice saved as {filename}") 25 | 26 | if __name__ == "__main__": 27 | data = pd.read_csv("orders.csv") 28 | for _, row in data.iterrows(): 29 | items = eval(row["items"]) 30 | generate_invoice(row["order_id"], row["customer_name"], items, row["total_amount"]) 31 | --------------------------------------------------------------------------------