Certificate Generator is a project I created to simplify the process of generating certificates when I am in charge of organizing events. Additionally, I have implemented functionality to send these certificates via email using Gmail.
- Python >=
3.10.xx
In the templates
folder, ensure you have the following three files:
MiriamLibre-SemiBold.ttf
nama-peserta.csv
sertifikat-peserta.png
Ensure the file names match the criteria mentioned above to prevent errors. This project also includes sample CSV and certificate files that were used to test and run the project.
For the CSV file, ensure it contains two columns named nama
and email
. The code is designed to work with CSV files that use semicolons (;
) as separators.
To create an email password, follow the instructions provided here: Google Mail Support.
After creating the password, store it in a secure location.
Note: Once you have sent all the generated certificates to the recipients, be sure to delete the password. This password is intended for one-time use only to minimize security risks.
- Install necessary modules
pip install -r requirements.txt
- Create the
output
folder where the generated certificate files will be stored.
mkdir output
To generate certificates, run the command below. Once the command is executed, wait for the program to complete the process. The generated certificates can be found in the output
folder.
python main.py
- If you want to customize the subject and body of the email, you can modify them in the send-mail.py file by updating the following function:
# Function to send email
def send_email(to_email, recipient_name):
subject = "Sertifikat Kehadiran"
body = f"""\
Selamat, {recipient_name}!
Sertifikat Kehadiran di anda sudah tersedia. Anda dapat mendownload pada attachment.
Terima kasih, semoga bermanfaat.
Salam,
Pengurus Event."""
- Copy the
.env.example
file and rename it to.env
, then configure it as follows:
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=<change to your username email>
SMTP_PASSWORD="<change to your password from App Password>"
- To start sending emails, run the following command and wait until all emails have been sent to the recipients
python send-email.py
If you'd like to use your own certificate design and font, you can make adjustments in the main.py
file.
- To change the font and adjust the font size to fit the certificate fields, modify the following code:
# Font configuration
font_path = "templates/MiriamLibre-SemiBold.ttf"
font_size = 85
By default, the participant's name is centered in the certificate name field.
- To adjust the horizontal position of the participant's name on the certificate, modify this code. Use
+
to move the name to the right and-
to move it to the left. Example:
# Horizontal position (centered by default)
text_x = (image_width - text_width) / 2 + 10
- To adjust the vertical position of the participant's name on the certificate, modify this code. Use
+
to move the name up and-
to move it down. Example:
# Vertical position (adjust as needed)
text_y = 500 + 40
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.