[reportlab-users] registerFont stays how long in memory? what s the best place to register a font?
thomasspin at gmail.com
Wed Apr 14 18:41:22 EDT 2010
I changed my code to loading the font based on if the _fonts variable has
the key Calibri. If not I load the font.
if not pdfmetrics._fonts.has_key('Calibri'):
pdfmetrics.registerFont(TTFont('Calibri', settings.FONT_DIR +
request.user.message_set.create(message='Font could not be read from
file system. Please try again or contact your system administrator.')
request.user.message_set.create(message='Font could not be loaded.
Please try again or contact your system administrator.')
This worked fine in my dev. settings and it worked fine in production now
for a day. But now I'm back to my old problem that the call
p.setFont("Calibri", 7) throws a keyError at about each 5th pdf generation
call, which is more than strange. The production server is an apache server
with modpython running.
I really have no clue what is wrong and I'm wondering whether this font
loading is maybe buggy?
Would appreciate any help!
2010/4/13 Robin Becker <robin at reportlab.com>
> On 13/04/2010 11:13, Thomas Kremmel wrote:
>> I'm wondering what is the best time to register a font for use in
>> I added the following line into my settings.py in django:
>> pdfmetrics.registerFont(TTFont('Calibri', FONT_DIR +
>> 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
>> after a few days the font is not available anymore and I have to restart
>> 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.
>> 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
>> 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
> 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 +
> Robin Becker
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the reportlab-users