Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d2d94b

Browse files
Merge pull request avinashkranjan#2691 from Yashika-Agrawal/Payment
Completed payment receipt project (avinashkranjan#2690)
2 parents 14d473a + a741426 commit 2d2d94b

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

‎Payment_Receipt/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Payment Receipt Generator
2+
3+
This project generates a PDF payment receipt using the ReportLab library in Python.
4+
5+
## Features
6+
7+
- Generates a PDF receipt with formatted data.
8+
- Uses ReportLab to create a professional-looking receipt.
9+
10+
## Usage
11+
12+
- Navigate to the project directory in your terminal.
13+
- Run the following command to generate the payment receipt PDF:
14+
$ python payment.py
15+
- The generated receipt PDF file will be saved as "receipt.pdf" in the same directory.

‎Payment_Receipt/payment.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# imports module
2+
from reportlab.platypus import SimpleDocTemplate, Table, Paragraph, TableStyle
3+
from reportlab.lib import colors
4+
from reportlab.lib.pagesizes import A4
5+
from reportlab.lib.styles import getSampleStyleSheet
6+
7+
# data which we are going to display as tables
8+
DATA = [
9+
[ "Date" , "Name", "Subscription", "Price (Rs.)" ],
10+
[
11+
"08/08/2023",
12+
"Full Stack Development with React & Node JS - Live",
13+
"Lifetime",
14+
"10,999.00/-",
15+
],
16+
[ "08/08/2023", "Data Structures and Algorithms: Live Session", "6 months", "9,999.00/-"],
17+
[ "Sub Total", "", "", "20,9998.00/-"],
18+
[ "Discount", "", "", "-3,000.00/-"],
19+
[ "Total", "", "", "17,998.00/-"],
20+
]
21+
22+
# creating a Base Document Template of page size A4
23+
pdf = SimpleDocTemplate( "receipt.pdf" , pagesize = A4 )
24+
25+
# standard stylesheet defined within reportlab itself
26+
styles = getSampleStyleSheet()
27+
28+
# fetching the style of Top level heading (Heading1)
29+
title_style = styles[ "Heading1" ]
30+
31+
# 0: left, 1: center, 2: right
32+
title_style.alignment = 1
33+
34+
# creating the paragraph with
35+
# the heading text and passing the styles of it
36+
title = Paragraph( "Your Payment Receipt" , title_style )
37+
38+
# creates a Table Style object and in it,
39+
# defines the styles row wise
40+
# the tuples which look like coordinates
41+
# are nothing but rows and columns
42+
style = TableStyle(
43+
[
44+
( "BOX" , ( 0, 0 ), ( -1, -1 ), 1 , colors.black ),
45+
( "GRID" , ( 0, 0 ), ( 4 , 4 ), 1 , colors.black ),
46+
( "BACKGROUND" , ( 0, 0 ), ( 3, 0 ), colors.gray ),
47+
( "TEXTCOLOR" , ( 0, 0 ), ( -1, 0 ), colors.whitesmoke ),
48+
( "ALIGN" , ( 0, 0 ), ( -1, -1 ), "CENTER" ),
49+
( "BACKGROUND" , ( 0 , 1 ) , ( -1 , -1 ), colors.beige ),
50+
]
51+
)
52+
53+
# creates a table object and passes the style to it
54+
table = Table( DATA , style = style )
55+
56+
# final step which builds the
57+
# actual pdf putting together all the elements
58+
pdf.build([ title , table ])

‎Payment_Receipt/receipt.pdf‎

2.16 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /