In a file called
shirtificate.py, implement a program that prompts the user for their name and outputs, using fpdf2, a CS50 shirtificate in a file called
shirtificate.pdf similar to this one for John Harvard, with these specifications:
- The orientation of the PDF should be Portrait.
- The format of the PDF should be A4, which is 210mm wide by 297mm tall.
- The top of the PDF should “CS50 Shirtificate” as text, centered horizontally.
- The shirt’s image should be centered horizontally.
- The user’s name should be on top of the shirt, in white text.
All other details we leave to you. You’re even welcome to add borders, colors, and lines. Your shirtificate needn’t match John Harvard’s precisely. And no need to wrap long names across multiple lines.
No need to submit any PDFs with your code. But, if you would like, you’re welcome (but not expected) to share a shirtificate with your name on it in any of CS50’s communities!
- Note that fpdf2 comes with a
FPDF, which has quite a few methods, per pyfpdf.github.io/fpdf2/fpdf/#fpdf.FPDF. You can install it with:
pip install fpdf2
- Note that you can extend
FPDFand instantiate your own subclass thereof in order to add a header to every page of a PDF, per pyfpdf.github.io/fpdf2/Tutorial.html#tuto-2-header-footer-page-break-and-image. Or you can add it as text yourself.
- Note that you can disable automatic page breaks, which might otherwise cause your PDF to overflow from one page to two, with
set_auto_page_break, per pyfpdf.github.io/fpdf2/Margins.html.
- Note that a cell’s height can be negative, to move it upward.
- You can open
shirtificate.pdf, once outputted, by clicking it in VS Code’s file explorer.
Before You Begin
Log into code.cs50.io, click on your terminal window, and execute
cd by itself. You should find that your terminal window’s prompt resembles the below:
to make a folder called
shirtificate in your codespace.
to change directories into that folder. You should now see your terminal prompt as
shirtificate/ $. Now execute
to get a copy of the
shirtificate.png image for your certificate. Finally, execute
to make a file called
shirtificate.py where you’ll write your program.
How to Test
Here’s how to test your code manually:
- Run your program with
shirtificate.py. Make sure your program prompts you for a name. Enter your own name and press Enter. Your program should create a file,
shirtificate.pdf, containing the name you entered as input overlaid on a rendering of
- Try a few other names for good measure, too!
You can execute the below to check your code using
check50, a program that CS50 will use to test your code when you submit. But be sure to test it yourself as well!
Green smilies mean your program has passed a test! Red frownies will indicate your program output something unexpected. Visit the URL that
check50 outputs to see the input
check50 handed to your program, what output it expected, and what output your program actually gave.
How to Submit
In your terminal, execute the below to submit your work.