I work for a company where we need to generate PDF certificates for our students. Currently, this task is being handled by manually editing and exporting the PDF files.
What I have built now works in a manner where my code fetches a Template Image and writes names and company name from an excel sheet.
The Issue: The text placed is not properly aligned due to string length.
import pandas as pd
from PIL import Image, ImageDraw, ImageFont
data = pd.read_excel(r'D:CDACCertificate GeneratorNames.xlsx')
name_list = data["Name"].tolist()
company_list = data["Company"].tolist()
store = len(name_list)
for i in range(0,store):
im = Image.open(r'D:CDACCertificate Generatorcdac certificate.jpg')
d = ImageDraw.Draw(im)
location = (350, 370)
text_color = (0, 0, 0)
font = ImageFont.truetype("times.ttf", 40)
d.text(location, name_list[i], fill = text_color, font = font)
location = (287, 411)
text_color = (0, 0, 0)
font = ImageFont.truetype("times.ttf", 40)
d.text(location, company_list[i], fill = text_color, font = font)
im.save("certificate_" + name_list[i] + ".pdf")
template image
enter image description here
question from:
https://stackoverflow.com/questions/66058426/how-do-i-generate-batches-of-pdf-for-course-completion-certificate 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…