Mark sheet in PDF using data from database

Mark sheet from database to PDF page

PDF Invoice generation in Python using Reportlab by using sales and product data using template

There are three files used and the library ReportLab is used to write the PDF file.

the file can be used to get data from different database and other data sources to generate the Invoice. Here some sample data is stored inside the file.

This file stores sample data for product and sales inside two dictionary and variables like tax rate discount rate are set here.

my_prod is a dictionary having product_id as key and product name , price as value list.
my_prod={1:['Hard Disk',80],2:['RAM',90],3:['Monitor',75],
         7:['Mother board',50],8:['Power Sypply',20],
my_sale is a dictionary having product_id as key and quantity sold as value.

We have discount and tax rate as variables inside this file.
discount_rate=10 # 10% discount 
tax_rate=12 # tax rate  in percentage

Mark sheet from database to PDF page
This is the template file where the blank design of the invoice is available inside the function my_temp(). This function is called inside the main file to show the blank invoice.

This file draws all lines , add text and place the top logo on the canvas. Font family is changed to available default fonts.

This is the main file and by using the template ( ) and the data ( ) it creates the pdf document.
from temp_invoice import my_temp # import the template
from invoice_data import *  # get all data required for invoice
By using for loop all sales data are displayed with quanity and price. Here for price and total drawRightString() is used.
for items in my_sale:
    c.drawString(0.1*inch,line_y*inch,str(my_prod[items][0])) # p Name
    c.drawRightString(4.5*inch,line_y*inch,str(my_prod[items][1])) # p Price
    c.drawRightString(5.5*inch,line_y*inch,str(my_sale[items])) # p Qunt 
    c.drawRightString(7*inch,line_y*inch,str(sub_total)) # Sub Total 

Python PDF PDF Mark sheet by using data from SQLite database Table from different data sources to PDF file Table from Pandas DataFrame to PDF file

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer