Mark sheet in PDF using data from database

PDF
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 invoice_data.py 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.

invoice_data.py

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],
         4:['CPU',55],5:['Keyboard',20],6:['Mouse',10],
         7:['Mother board',50],8:['Power Sypply',20],
         9:['Speaker',50],10:['Microphone',45]}
my_sale is a dictionary having product_id as key and quantity sold as value.

my_sale={1:2,3:2,7:1,4:3,6:5,5:3,2:1,9:1,10:3}
We have discount and tax rate as variables inside this file.
discount_rate=10 # 10% discount 
tax_rate=12 # tax rate  in percentage 

temp_invoice.py

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.

invoice.py

This is the main file and by using the template ( temp_invoice.py ) and the data ( invoice_data.py ) 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 
    sub_total=my_prod[items][1]*my_sale[items]
    c.drawRightString(7*inch,line_y*inch,str(sub_total)) # Sub Total 
    total=round(total+sub_total,1)
    line_y=line_y-row_gap
invoice_data

temp_invoice.py

invoice.py

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

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    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-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer