[reportlab-users] Font Helvetica always used?

Robin Becker robin at reportlab.com
Thu Jun 18 08:08:29 EDT 2015

On 17/06/2015 20:55, Glenn Linderman wrote:
> On 6/17/2015 5:09 AM, Robin Becker wrote:
>> If you don't want to mess with the settings overrides then this code at the
>> start of your initial script should do the trick
> So what is the real restriction?  This has to be done before what? Before first
> canvas instantiation, or before other imports, or before what, specifically?
The Canvas class needs a default fontname at instantiation. It can be passed in, 
but if the default None is present we use


however, it's fairly obvious that we need to ensure the font exists at the time 
of first use. With our existing simple rl_config module that's hard to do in one 

I did some experiments with the technique blessed by GvR here


and it seems if we adopted this technique we could then use a more simple 
mechanism like this in our settings file overrides so  in one of

>    i: reportlab/rl_local_settings.py
>   ii: reportlab_settings.py  somewhere on the PYTHONPATH.
>  iii: ~/.reportlab_settings.py for unix like systems.

you could do this

def canvas_basefontname():
     from reportlab.pdfbase.ttfonts import TTFont
     from reportlab.pdfbase.pdfmetrics import registerFont, registerFontFamily
     return 'arial'

and the rl_config object could check for and defer evaluation until the first 
import/use of rl_config.canvas_basefontname. This avoids circular importing 
which happens otherwise.
Robin Becker

More information about the reportlab-users mailing list