[reportlab-users] PDF created in ReportLab looks awesome in Foxit, awful in Adobe

Marc Tompkins marc.tompkins at gmail.com
Fri Jul 13 21:53:52 EDT 2012

On Thu, Jul 12, 2012 at 4:30 PM, Marc Tompkins <marc.tompkins at gmail.com>wrote:

> The problem may be that I'm registering and using Consolas (a TrueType

> font bundled with Windows) rather than one of the built-in fonts; I need a

> monospaced font that retains readability at 8 points or so, and Courier

> just isn't cutting it.



Just thought I'd follow up with my workaround... As I said, I need a
monospaced font that looks good at 8 points or so (I didn't previously
mention that I'm bolding certain fields for improved readability - so the
font needs to have a Bold face); it looks like I'm going to need to
distribute that font rather than assume that the user has it already, so I
went looking for free/libre fonts that would fit the bill. I found nine;
I'm going to present the user with a drop-down list and render my report
My main report (an insurance EOB) is a lot more involved than the sample I
sent; I originally laid the thing out to fit 128 columns on a page in
Consolas 8-point, and some of the fonts I found render bigger or smaller
than Consolas - so I had to adjust the size accordingly. Here's what I
came up with (I'll change the paths in production, of course):

pdfDir = os.path.join(os.path.expanduser('~'), 'Desktop', 'PDFs')
fontDir = os.path.join(os.path.expanduser('~'), 'Desktop', 'Fonts')

fontSetting = {'Anonymous Pro': ('Anonymous_Pro.ttf',
'Anonymous_Pro_B.ttf', 8),
'Bitstream Vera Sans Mono': ('VeraMono.ttf',
'VeraMono-Bold.ttf', 7.3),
'BPMono': ('BPMono.ttf', 'BPMonoBold.ttf', 7.3),
'Cousine': ('Cousine-Regular-Latin.ttf',
'Cousine-Bold-Latin.ttf', 7.3),
'DejaVu Sans': ('DejaVuSansMono.ttf',
'DejaVuSansMono-Bold.ttf', 7.3),
'Lekton': ('Lekton-Regular.ttf', 'Lekton-Bold.ttf', 8.7),
'Liberation Mono': ('LiberationMono-Regular.ttf',
'LiberationMono-Bold.ttf', 7.3),
'Luxi-Mono': ('luximr.ttf', 'luximb.ttf', 7.3),
'Ubuntu Mono': ('UbuntuMono-R.ttf', 'UbuntuMono-B.ttf',

fFont = 'Bitstream Vera Sans Mono' #in production, this would be the
user's selection

regFont = fFont
boldFont = fFont + ' Bold'
fontSize = fontSetting[fFont][2]
fileNameReg = fontDir + os.sep + fontSetting[fFont][0]
fileNameBold = fontDir + os.sep + fontSetting[fFont][1]
pdfmetrics.registerFont(TTFont(regFont, fileNameReg))
pdfmetrics.registerFont(TTFont(boldFont, fileNameBold))

Each of these fonts renders my report properly in both the Foxit and Adobe
Readers; many others that I tried did not. Also, each of them is licensed
to allow commercial use/distribution (generally as long as you include the
license file), which many others were not. I'm afraid I didn't keep notes
of the sites where I found them, but the names ought to be enough for

Just thought I'd post this follow-up for the benefit of future sufferers...

Thanks for a wonderful package, by the way!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20120713/16255d29/attachment.htm>

More information about the reportlab-users mailing list