Mark sheet in PDF using data from database

Mark sheet from database to PDF page

Generate PDF Mark sheet of students using data from SQLite or MySQL table using Python Reportlab

We will create this sample mark sheet by using data from SQLite ( or MySQL ) database student table.

We used two files for this script, the file creates the canvas and uses the template file to generate the PDF file with data.
Copy the source code of these files at the end of this page.

Data Source

We will use SQLite database student table.
Script can easily changed to get data from MySQL database table.
Download sample SQLite database with student table
We can also use MySQL database.

Database connection and getting data

We used try except error handling to show error message.
from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError
db_file='G:\\My drive\\testing\\my_db.db'  
    file1='sqlite:///'+ db_file 
    my_conn = create_engine(file1)
    # For MySQL use the below line and remove the above lines for SQLite file
    #my_conn = create_engine("mysql+mysqldb://root:pw@localhost/my_tutorial")    
    r_set=my_conn.execute("SELECT *  FROM student WHERE id =6")
except SQLAlchemyError as e:
    error = str(e.__dict__['orig'])

Python PDF Generate PDF Invoice using Sales data 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-2022 All rights reserved worldwide Privacy Policy Disclaimer