Skip to content

Instantly share code, notes, and snippets.

@iniakunhuda
Last active December 16, 2023 13:32
Show Gist options
  • Save iniakunhuda/3aa9d766fac1fe6ca08050a82f7df857 to your computer and use it in GitHub Desktop.
Save iniakunhuda/3aa9d766fac1fe6ca08050a82f7df857 to your computer and use it in GitHub Desktop.
Generate Certificate From CSV to PDF
from PIL import Image, ImageFont, ImageDraw
import pandas as pd
def main():
print("Initializing Script!")
names = pd.read_csv('peserta-devfest2023.csv')
for i,row in names.iterrows():
name = str(row['Name'])
name = name.title()
word_length = len(name.split(" "))
empty_img = Image.open("sertif.png").convert("RGB")
if(word_length > 4):
font_size = 70
bottom = -50
else:
font_size = 80
bottom = -50
W,H = empty_img.size
font = ImageFont.truetype(r"OpenSans.ttf", font_size)
(_, _, w, h) = font.getbbox(name)
width = ((W-w)/2)
height = ((H-h)/2) + bottom
image_editable = ImageDraw.Draw(empty_img)
image_editable.multiline_text((width,height), name, (35, 57, 75), font=font)
empty_img.save("hasil/{}.pdf".format(name.replace(" ", "_")))
print('Processed {} Rows'.format(i))
print("Process Complete!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment