[reportlab-users] Problem printing with lulu.com

Robin Becker robin at reportlab.com
Thu Apr 15 04:56:19 EDT 2010

On 14/04/2010 13:26, Andy Robinson wrote:

> We've decided on a couple of changes here.


> - those people printing in environments where all fonts should be

> embedded should have a way to register not only a base font but also a

> font family (as we need bold and italic) on startup

> - getSampleStyleSheet() can then use this

> - anything else needing a default font will take it from the config


> Hopefully this will eliminate stray occurrences of Helvetica and

> Times-Roman, and still make it easy enough to get a usable stylesheet

> without making a copy of it.


> Robin will post the list when this is in place


> - Andy


OK I have made some changes to reportlab/lib/styles.py and tables.py (the main
culprit) so that for the canvas the standard fonts will all be derived from the
canvas_basefontname variable in rl_config.py. If you use one of the 'standard'
font names such as Courier, Helvetica or Times-Roman then a font family will
automagically appear in the sample stylesheet. Also there will be variables
called reportlab.lib.styles._baseFontName, _baseFontNameB, _baseFontNameI &
_baseFontNameBI which can be explicitly imported.

If you decide to use another font name then you will have to explicitly register
suitable font(s) and also do a registerFontFamily eg

from reportlab.pdfbase import pdfmetrics, ttfonts
pdfmetrics.registerFont(ttfonts.TTFont("Vera", "Vera.ttf"))
pdfmetrics.registerFont(ttfonts.TTFont("VeraBd", "VeraBd.ttf"))
pdfmetrics.registerFont(ttfonts.TTFont("VeraIt", "VeraIt.ttf"))
pdfmetrics.registerFont(ttfonts.TTFont("VeraBI", "VeraBI.ttf"))

this will need to be done prior to creating a canvas or getting the style sheet
etc etc (ie early in the process).

I've tested Robert's script with this latest code and thankfully we do get rid
of Times-Roman in favour of Vera etc etc.

The same kind of logic has been applied to the graphics base font
(rl_config.defaultGraphicsFontName) a bit more thoroughly although for now that
stays defaulted to 'Times-Roman'. Charts are more sensitive to font size so it's
probably unwise to change to Helvetica.
Robin Becker

More information about the reportlab-users mailing list