Amazing-Python-Scripts

Форк
0
59 строк · 1.8 Кб
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",
17
        "6 months", "9,999.00/-"],
18
    ["Sub Total", "", "", "20,9998.00/-"],
19
    ["Discount", "", "", "-3,000.00/-"],
20
    ["Total", "", "", "17,998.00/-"],
21
]
22

23
# creating a Base Document Template of page size A4
24
pdf = SimpleDocTemplate("receipt.pdf", pagesize=A4)
25

26
# standard stylesheet defined within reportlab itself
27
styles = getSampleStyleSheet()
28

29
# fetching the style of Top level heading (Heading1)
30
title_style = styles["Heading1"]
31

32
# 0: left, 1: center, 2: right
33
title_style.alignment = 1
34

35
# creating the paragraph with
36
# the heading text and passing the styles of it
37
title = Paragraph("Your Payment Receipt", title_style)
38

39
# creates a Table Style object and in it,
40
# defines the styles row wise
41
# the tuples which look like coordinates
42
# are nothing but rows and columns
43
style = TableStyle(
44
    [
45
        ("BOX", (0, 0), (-1, -1), 1, colors.black),
46
        ("GRID", (0, 0), (4, 4), 1, colors.black),
47
        ("BACKGROUND", (0, 0), (3, 0), colors.gray),
48
        ("TEXTCOLOR", (0, 0), (-1, 0), colors.whitesmoke),
49
        ("ALIGN", (0, 0), (-1, -1), "CENTER"),
50
        ("BACKGROUND", (0, 1), (-1, -1), colors.beige),
51
    ]
52
)
53

54
# creates a table object and passes the style to it
55
table = Table(DATA, style=style)
56

57
# final step which builds the
58
# actual pdf putting together all the elements
59
pdf.build([title, table])
60

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.