[reportlab-users] True Type fonts - newbie question

Glenn Linderman v+python at g.nevcal.com
Mon May 16 05:08:27 EDT 2011


Trying to access other fonts in ReportLab, because Times doesn't have
them all...

Used the following, sort of from user guide section 3.5, but the new
font doesn't show up in the list, and although this sample doesn't
produce an error from the setFont, when I embed in a larger program,
sometimes it does... after the print !?

But the issue is how can I add a TT font and get it registered, and show
up in the list?

#!c:\python26\python.exe
# -*- coding: utf-8 -*-

import sys, os, re, getopt
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import LETTER, A4, LEGAL, ELEVENSEVENTEEN
from reportlab.lib.units import cm, mm, inch, pica
def list_available_fonts():
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('Times-New-Roman',
'c:\\windows\\fonts\\times.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanBd',
'c:\\windows\\fonts\\timesBd.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanIt',
'c:\\windows\\fonts\\timesI.ttf'))
pdfmetrics.registerFont(TTFont('Times-New-RomanBI',
'c:\\windows\\fonts\\timesBI.ttf'))
pdf = Canvas(sys.stdout)
pdf.setFont('Times-New-Roman', 16)
all_fonts = pdf.getAvailableFonts()
print all_fonts

list_available_fonts()


More information about the reportlab-users mailing list