[reportlab-users] registerFont stays how long in memory? what s the best place to register a font?
robin at reportlab.com
Tue Apr 13 06:51:07 EDT 2010
On 13/04/2010 11:13, Thomas Kremmel wrote:
> I'm wondering what is the best time to register a font for use in reportlab.
> I added the following line into my settings.py in django:
> pdfmetrics.registerFont(TTFont('Calibri', FONT_DIR + '/fonts/Calibri.ttf'))
> the settings.py is called the first time when the server starts.
> After this call the font is available for pdf generation. But it occurs that
> after a few days the font is not available anymore and I have to restart the
> django app, which leads to a re-registering of the font.
> One approach I already tried was registering the font before each pdf
> generation call, which did not worked since it crashed each 3-5 call. Thats
> the reason why I put it in a place which is just called once at the
> I just want to know if the settings.py is the correct place to register a
> font for reportlab and if yes, what could be the reason that the font is not
> available after a few days anymore!?
> would be great to find some help here!
well I wouldn't use the django settings.py file to do this; it's supposed to be
executed just once, but your observation shows that there can be problems.
How about checking at the startup to see if the font is already present
if not pdfmetrics._fonts.has_key('Calibri'):
pdfmetrics.registerFont(TTFont('Calibri', FONT_DIR + '/fonts/Calibri.ttf'))
More information about the reportlab-users