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 import pandas
import pandas as pd
After importing pandas, we have to import pillow package for using Image and Font
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 a name_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")
One thing I want to clear that for i in name_list i 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 to view section and tick the status bar. It shows the position of the mouse on the image on the down side.
Then give the text color in RGB. Then in font variable type the font name you want to use and using comma type the font size.
In the last line, you see the code
im.save("certificate_" + i + ".pdf")
It will save all your certificates in PDF manner. Here i is the name to the attendee. It will save like certificate_Rahul Sinha.pdf
- Note - All the PDF file save where your python code will be.
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