0% found this document useful (0 votes)
10 views2 pages

code2pdf_666f122956a03

The document is a Python script that generates a PDF invoice for a coaching centre using the FPDF library. It includes details such as the order number, date, total amount, payment method, product information, teacher's name, and coaching centre contact information. The generated PDF is saved with a unique order number in the file path specified.

Uploaded by

Jatin Sarda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

code2pdf_666f122956a03

The document is a Python script that generates a PDF invoice for a coaching centre using the FPDF library. It includes details such as the order number, date, total amount, payment method, product information, teacher's name, and coaching centre contact information. The generated PDF is saved with a unique order number in the file path specified.

Uploaded by

Jatin Sarda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

class PDF(FPDF):

def header(self):
self.set_font('Arial', 'B', 12)
self.cell(0, 10, 'Coaching Centre Invoice', 0, 1, 'C')

def footer(self):
self.set_y(-15)
self.set_font('Arial', 'I', 8)
self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')

# Define the invoice details


order_number = random.randint(1000, 9999)
date = "12/06/2024"
total = "Rs. 15,100.00"
payment_method = "Credit Card/Debit Card/NetBanking"
product = "AFM (Advanced Financial Management)"
price = "Rs. 15,100.00"
teacher_name = "Sanjay Saraf"
coaching_centre_name = "Elite Coaching Centre"
address = "123 Main Street, City, Country"
contact = "+123 456 7890"

# Create a PDF document


pdf = PDF()
pdf.add_page()

# Add coaching centre details


pdf.set_font("Arial", size=12)
pdf.cell(0, 10, coaching_centre_name, 0, 1, 'C')
pdf.cell(0, 10, address, 0, 1, 'C')
pdf.cell(0, 10, contact, 0, 1, 'C')
pdf.ln(10)

# Add the first section with order number, date, total, and payment method
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Order number:", ln=True)
pdf.set_font("Arial", size=14, style='B')
pdf.cell(200, 10, txt=str(order_number), ln=True)

pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Date:", ln=True)
pdf.set_font("Arial", size=14, style='B')
pdf.cell(200, 10, txt=date, ln=True)

pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Total:", ln=True)
pdf.set_font("Arial", size=14, style='B')
pdf.cell(200, 10, txt=total, ln=True)

pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt="Payment method:", ln=True)
pdf.set_font("Arial", size=14, style='B')
pdf.cell(200, 10, txt=payment_method, ln=True)

# Add a spacer
pdf.cell(200, 10, txt="", ln=True)

# Add the order details section


pdf.set_font("Arial", 'B', size=12)
pdf.cell(0, 10, txt="Order details", ln=True)

pdf.set_font("Arial", size=12)
pdf.cell(100, 10, txt="Product", border=1)
pdf.cell(0, 10, txt="Total", border=1, ln=True, align="R")

pdf.cell(100, 10, txt=product, border=1)


pdf.cell(0, 10, txt=price, border=1, ln=True, align="R")

pdf.cell(0, 10, txt="Teacher name: " + teacher_name, ln=True)

# Add the payment method and total at the bottom


pdf.cell(200, 10, txt="", ln=True) # Empty line
pdf.cell(200, 10, txt="Payment method:", ln=True)
pdf.set_font("Arial", size=14, style='B')
pdf.cell(200, 10, txt=payment_method, ln=True)
pdf.cell(200, 10, txt="Total:", ln=True)
pdf.set_font("Arial", size=14, style='B')
pdf.cell(200, 10, txt=total, ln=True)

# Save the PDF to a file


file_path = "/mnt/data/invoice_professional_{}.pdf".format(order_number)
pdf.output(file_path)

file_path

You might also like