Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new fonts #96

Open
jstnjy opened this issue Feb 11, 2020 · 2 comments
Open

Adding new fonts #96

jstnjy opened this issue Feb 11, 2020 · 2 comments

Comments

@jstnjy
Copy link

jstnjy commented Feb 11, 2020

Hi sir @szabgab, I see a code of how to write a text in pdf using python here https://code-maven.com/creating-pdf-files-using-python. my concern is this

from reportlab.pdfgen import canvas
 
pdf_file = 'hello_world_fonts.pdf'
 
can = canvas.Canvas(pdf_file)
 
print(can.getAvailableFonts())
# 'Courier', 'Courier-Bold', 'Courier-BoldOblique', 'Courier-Oblique',
# 'Helvetica', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Helvetica-Oblique',
# 'Symbol',
# 'Times-Bold', 'Times-BoldItalic', 'Times-Italic', 'Times-Roman',
# 'ZapfDingbats'
 
can.setFont("Helvetica", 24)
can.drawString(20, 400, "Hello")
can.drawString(40, 360, "World")
 
can.setFont("Courier", 16)
can.drawString(60, 300, "How are you?")
 
can.showPage()
can.save()

How can I add a font on the list? like Cambria.
thank you

@szabgab
Copy link
Owner

szabgab commented Feb 13, 2020

I am not good at fonts, but do you have it installed on your computer? Where is it located?

@jstnjy
Copy link
Author

jstnjy commented Feb 13, 2020

@szabgab, thank you for your reply. I managed to solve this by downloading another font with a ttf extension file name. I just got confused since the only true type fonts that can be registered using report lab are on this list https://nationalband.com/wp-content/uploads/2015/04/fontlist.pdf. I just tried to download a font with a ttf extension and then it works. I appreciate your reply thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants