VOOZH about

URL: https://www.geeksforgeeks.org/python/creating-payment-receipts-using-python/

⇱ Creating payment receipts using Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Creating payment receipts using Python

Last Updated : 18 Apr, 2026

Creating payment receipts is a common task, whether for an e-commerce website, a local store, or any business. In this article, we will learn how to generate transaction receipts as PDF files using Python.

We will use the reportlab library to create PDFs with tables, styles and headings.

Installation

Install "ReportLab" library using the following pip command:

pip install reportlab

Step-Wise Implementation

1. Import Required Modules: Import all the Python libraries needed to create the PDF, tables, and styles.

2. Prepare Data: The data for the receipt is organized in a list of lists. The first row contains the table headers.

3. Create PDF Template: We create a base PDF document named receipt.pdf and set its page size to standard A4 dimensions.

4. Create Styles: Use ReportLab’s built-in sample style sheet and adjust the heading style.

Here, alignment = 1 centers the title on the page.

5. Create the Title: Create a title paragraph for the PDF.

6. Create Table Style: Define the style for the table, including borders, grid lines, header color, text alignment, and background color.

Explanation:

  • BOX: Draws a border around the entire table.
  • GRID: Adds grid lines between all cells.
  • BACKGROUND (0,0 to -1,0): Sets the header row’s background color to gray.
  • TEXTCOLOR (0,0 to -1,0): Sets the header row text color to white.
  • ALIGN: Centers text in all cells.
  • BACKGROUND (0,1 to -1, -1): Sets the background color of all data rows to beige.

7. Create the Table: Create the table object and apply the style.

8. Build the PDF: Combine the title and table and build the PDF.

Output

👁 Image
receipt.pdf
Comment
Article Tags: