[reportlab-users] registering font does not work after switching media server

Thomas Kremmel thomasspin at gmail.com
Thu Mar 25 08:39:50 EDT 2010


For other interested people with the same problem. This would be the
solution:

in your settings.py:

#with this settings you can use MEDIA_ROOT setting to access files in the
media folder of your project.
import os.path
PROJECT_DIR = os.path.dirname(__file__)
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')

this is how to use the setting and register a font in order to use it by
reportlab:

pdfmetrics.registerFont(TTFont('Calibri', settings.MEDIA_ROOT +
'/fonts/calibri.ttf'))

2010/3/25 Thomas Kremmel <thomasspin at gmail.com>


> Oh yes... that helped! Thank you. That saved my working day ;-)

>

> 2010/3/25 Andy Robinson <andy at reportlab.com>

>

>> On 25 March 2010 11:31, Thomas Kremmel <thomasspin at gmail.com> wrote:

>>

>> > Tried it like this:

>> > pdfmetrics.registerFont(TTFont('Calibri',

>> > 'my_project/media/fonts/calibri.ttf'))

>> > or

>> > pdfmetrics.registerFont(TTFont('Calibri-Bold',

>> > 'media/fonts/calibri-bold.ttf'))

>> > But anyway, thats more a server question, than a reportlab question ;-)

>>

>> You need to provide an absolute path. Otherwise, it looks relative to

>> the 'current working directory'; if doing "manage.py runserver" that's

>> inside your project code, but inside Apache it could be '/' or

>> somewhere else unpredictable.

>>

>> All our settings.py files tend to have a variable MEDIA_DIR set to the

>> disk location of the files, rather than the URL; we'd build the full

>> pathname to the fonts using this.

>>

>> Hope this helps,

>>

>> 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/20100325/d6fd9619/attachment.html>


More information about the reportlab-users mailing list