[reportlab-users] registerFont stays how long in memory? what s the best place to register a font?

Thomas Kremmel thomasspin at gmail.com
Thu Apr 15 13:03:43 EDT 2010


Sorry was wrong with the fonts. Fonts are read from the file system..
But it would work using a http:// instead of a file system path. I used that
once and it worked, but in this list a user told me that I should not do it
that way ;-) Thus fonts are read from the file system.

Yes I would agree with you that things should fail either all the time or
never.
I advised my admin to complete re-install rl with all libs in the rl_addons
package and the result is that everything worked as before. PDF generation
is running smoothly and 100% of the calls are successfully conducted. This
was how my source behaved the day before yesterday. Then after one day the
strange behavior started. Thus I will try tomorrow whether this problems
reoccur. For your information, _rl_accel was already installed before. Thus
that has nothing to do with my problems.

Here is a list of additional information one could need to understand the
problem:

environment:
apache with mod_wsgi
django 1.1.1


Reportlab version 2.4
_rl_accel.pyd installed

1. ReportLab Toolkit - open source PDF library... version 2.4
(in C:\Python25\lib\site-packages\reportlab\__init__.pyc)

2. _rl_accel extension module... found version 0.61
(in C:\Python25\lib\site-packages\_rl_accel.pyd)

3. Python Imaging Library... found
(in C:\Python25\lib\site-packages\PIL)

4. _renderPM extension module... found version 1.06
(in C:\Python25\lib\site-packages\_renderPM.pyd)

5. pyRXP xml parser... not found


!simpliefied! django view:

def export_objects_as_pdf(request, model, object_list, user_object,
project_name, filename, month, year, billing_company, work_day_print_switch,
work_place_print_switch, LIST_HEADERS=None):
rl_config.warnOnMissingFontGlyphs = 0

try:
if not pdfmetrics._fonts.has_key('Calibri'):
pdfmetrics.registerFont(TTFont('Calibri', settings.FONT_DIR +
'/fonts/Calibri.ttf'))
pdfmetrics.registerFont(TTFont('Calibri-Bold', settings.FONT_DIR
+ '/fonts/Calibri-bold.ttf'))
if settings.WSGI_LOGGING is True:
print >> request.environ['wsgi.errors'], "view:
export_objects_as_pdf: info: pdfmetrics._fonts.has_key('Calibri') is False -
Successfully registered Calibri and Calibri-Bold Font"
else:
if settings.WSGI_LOGGING is True:
print >> request.environ['wsgi.errors'],
"pdfmetrics._fonts.has_key('Calibri') is True"
except Exception, e:
if settings.WSGI_LOGGING is True:
print >> request.environ['wsgi.errors'], "view:
export_objects_as_pdf: info: error while registering font"
print >> request.environ['wsgi.errors'], str(e)
request.user.message_set.create(message='Font could not be read from
file system. Please try again or contact your system administrator.')
return 0

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % filename
buffer = StringIO()
PAGESIZE = pagesizes.portrait(pagesizes.A4)

#COLOR definition
my_gray = colors.Color(.82,.82,.82)

try:
company_cd_color1_rr = float(billing_company.cd_colour1_rr) /
float(255)
company_cd_color1_gg = float(billing_company.cd_colour1_gg) /
float(255)
company_cd_color1_bb = float(billing_company.cd_colour1_bb) /
float(255)
company_cd_color1 =
colors.Color(company_cd_color1_rr,company_cd_color1_gg,company_cd_color1_bb)
except Exception:
#print "value error in creating colors"
request.user.message_set.create(message='Company Color could not be
loaded. Please contact your system administrator.')
company_cd_color1 = colors.Color(0,0,0)

# Create the PDF object, using the StringIO object as its "file."
p = canvas.Canvas(buffer,pagesize=PAGESIZE)
try:
p.setFont("Calibri", 7)
print >> request.environ['wsgi.errors'], "view:
export_objects_as_pdf: info: p.setFont('Calibri', 7) was successfull"
except KeyError, e:
if settings.WSGI_LOGGING is True:
print >> request.environ['wsgi.errors'], "view:
export_objects_as_pdf: info: error in line p.setFont('Calibri', 7)"
print >> request.environ['wsgi.errors'], str(e)
request.user.message_set.create(message='Font could not be loaded.
Please try again or contact your system administrator.')
return 0

try:
path = fetch_resources(billing_company.logo_img.path)
company_img = Image(path,40,7)
company_img.drawOn(p, 500, 790)
except:
#could not find file
request.user.message_set.create(message='Company Logo could not be
loaded. Please contact your system administrator.')
pass
#here we draw the pdf .. removed it since i just want to show the
relevant parts

# Close the PDF object cleanly.
p.showPage()
p.save()

# Get the value of the StringIO buffer and write it to the response.
pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response


!WSGI Logging!

[Thu Apr 15 00:18:44 2010] [error] [client 127.0.0.1] view:
export_objects_as_pdf: info: pdfmetrics._fonts.has_key('Calibri') is False -
Successfully registered Calibri and Calibri-Bold Font
[Thu Apr 15 00:18:44 2010] [error] [client 127.0.0.1] view:
export_objects_as_pdf: info: p.setFont('Calibri', 7) was successfull

[Thu Apr 15 00:26:07 2010] [error] [client 127.0.0.1]
pdfmetrics._fonts.has_key('Calibri') is True
[Thu Apr 15 00:26:07 2010] [error] [client 127.0.0.1] view:
export_objects_as_pdf: info: p.setFont('Calibri', 7) was successfull
[Thu Apr 15 00:26:08 2010] [error] [client 127.0.0.1]
pdfmetrics._fonts.has_key('Calibri') is True
[Thu Apr 15 00:26:08 2010] [error] [client 127.0.0.1] view:
export_objects_as_pdf: info: p.setFont('Calibri', 7) was successfull

This logging is how it should behave. I will check the logs tomorrow when
the error occurs again how the login changes and will post it here.
best regards
Thomas





2010/4/15 Andy Robinson <andy at reportlab.com>


> On 15 April 2010 14:17, Thomas Kremmel <thomasspin at gmail.com> wrote:

> >>> Is there just one machine, or some kind of a cluster?

> > one machine, but static content (like fonts, pictures) are served via a

> > separate server.

>

> Images I understand, but fonts? We have always loaded our fonts off

> the server file system. Is your settings.FONTDIR some kind of

> 'http://' URL instead of a file system path? This MIGHT work - I

> don't know - but it's your server side that needs the font, not their

> browser.

>

>

> > _rl_accel

> I'm still very surprised at the inconsistency. Please let us know in

> a day or two if it's stable. If so we still have an issue to look

> into. IMHO if _rl_accel is missing then either things should fail

> obviously 100% of the time (with a clue in the traceback), or work

> robustly but just a bit slower.

>

> - Andy

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100415/0140deaa/attachment.html>


More information about the reportlab-users mailing list