
Most have you thought that I could generate a certificate automatically for the attendees. This was my problem also because being a Microsoft Student Partner I tool many virtual events. So creating certificates are the most headache things I ever saw.
Then I got the idea to develop a program that generates certificates automatically. I go with python because it is very dynamic in use and when we create very long codes in a short format in python.
Let's Start writing our Code!
The first things are we have toimport pandas. Because we will be dealing with the excel sheets where are the names of the attendees are there. Like I have a created a demo excel sheet.
Let's importpandas
import pandas as pd
After importing pandas, we have to importpillow package for usingImage andFont
from PIL import Image, ImageDraw, ImageFont
Now, we have read our excel file. We will use the panda read_excel function here to read the data.
data = pd.read_excel(r,'C:\Users\Rahul sinha\names.xlsx')
- Note - place "r" before the path string to address special character, such as '\'. Place your whole where your file is saved.
Now create aname_list variable where all the names of the attendees will be saved.
name_list = data["Name"].tolist()
Here, you see"Name", it is the name of the column under which all the attendee names are there. Basically we are indexing all the names. Then converting all the names to the list.
Now we have to use a loop to print all the certificates of the attendees present in the excel sheet.
I am sharing the whole code.
for i in name_list: im = Image.open(r'C:\Users\Rahul sinha\certificate_img.jpg') d = ImageDraw.Draw(im) location = (100, 398) text_color = (0, 137, 209) font = ImageFont.truetype("arial.ttf", 120) d.text(location, i, fill = text_color, font = font) im.save("certificate_" + i + ".pdf")
I am explaning the whole code one by one. First I open the certificate image usingImage.open. Here is the screenshot of the demo certificate.
One thing I want to clear thatfor i in name_listi is all the names of the attendees.
For the location, we can use paint to point where our names should be printed. Open Paint. Go toview section and tick thestatus bar. It shows the position of the mouse on the image on the down side.
Then give the text color inRGB. Then infont variable type the font name you want to use and using comma type thefont size.
In the last line, you see the code
im.save("certificate_" + i + ".pdf")
It will save all your certificates in PDF manner. Herei is the name to the attendee. It will save likecertificate_Rahul Sinha.pdf
- Note - All the PDF file save where your python code will be.
Let's run our code and see the output.
You can see in the image all the names in the excel sheet have been printed. Let's see the final output by opening the PDF.
- Here is repo on GitHub of this code
rahulsinha036 / Generate-Certificate-using-Python3
A python script which helps to generate certificate for the attendee
Hurray!! You successfully generated your certificate using Python. I am a working GUI Certificate Generator Using Python. It will be an open-source project. If you love this blog do share with your friends and team-mates
Top comments(1)
For further actions, you may consider blocking this person and/orreporting abuse