Discussion:
[reportlab-users] registering font does not work after switching media server
Thomas Kremmel
2010-03-25 11:00:09 UTC
Permalink
Hi,

I m developing a django app using reportlab. Till now I just used the django
development server to serve all media files, including some ttf fonts to be
registered by reportlab. I do it like this:

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

That worked fine till I switched from the django development server to
apache production server. Now I'm getting the error:

TTFError at /accounting/export/do/

Not a TrueType font: version=0x3C21444F


This is strange since it does work with the development server and
using the apache server i get an error from reportlab.. humm. this
error should not be related to the server, but somehow it seems to
be...


ah yes.. The links to the fonts seem to be correct.

Hope to find some help here.

Best regards

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100325/e92ad4d8/attachment.html>
Roberto Alsina
2010-03-25 11:07:58 UTC
Permalink
Post by Thomas Kremmel
Hi,
I m developing a django app using reportlab. Till now I just used the
django development server to serve all media files, including some ttf
pdfmetrics.registerFont(TTFont('Calibri', settings.MEDIA_URL +
'fonts/calibri.ttf'))
That worked fine till I switched from the django development server to
TTFError at /accounting/export/do/
Not a TrueType font: version=0x3C21444F
This is strange since it does work with the development server and
using the apache server i get an error from reportlab.. humm. this
error should not be related to the server, but somehow it seems to
be...
ah yes.. The links to the fonts seem to be correc
If you are using a red hat variant or clone, and the font is outside /var/www
it may be that SELinux is not letting you read the file?
Thomas Kremmel
2010-03-25 11:09:37 UTC
Permalink
Thanks for your answer.
I'm using win xp and I can download the font via the web-browser. Thus it
seems that the apache does serve the file correctly. At least via the
web-browser.

2010/3/25 Roberto Alsina <ralsina at netmanagers.com.ar>
Post by Roberto Alsina
Post by Thomas Kremmel
Hi,
I m developing a django app using reportlab. Till now I just used the
django development server to serve all media files, including some ttf
pdfmetrics.registerFont(TTFont('Calibri', settings.MEDIA_URL +
'fonts/calibri.ttf'))
That worked fine till I switched from the django development server to
TTFError at /accounting/export/do/
Not a TrueType font: version=0x3C21444F
This is strange since it does work with the development server and
using the apache server i get an error from reportlab.. humm. this
error should not be related to the server, but somehow it seems to
be...
ah yes.. The links to the fonts seem to be correc
If you are using a red hat variant or clone, and the font is outside /var/www
it may be that SELinux is not letting you read the file?
_______________________________________________
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/1cd7628a/attachment.html>
Andy Robinson
2010-03-25 11:18:07 UTC
Permalink
Post by Thomas Kremmel
Hi,
I m developing a django app using reportlab. Till now I just used the django
development server to serve all media files, including some ttf fonts to be
pdfmetrics.registerFont(TTFont('Calibri', settings.MEDIA_URL +
'fonts/calibri.ttf'))
That worked fine till I switched from the django development server to
I never even realised we could load fonts from URLs! I guess we're
doing some transformation on the URLs.

Is your production MEDIA_URL relative, or on some other domain
("http://media.mydomain.com/fonts") ?

Also, out of curiosity, if the fonts are on the same box, why don't
you load them from the file system to save all the HTTP negotiation?

- Andy
Thomas Kremmel
2010-03-25 11:31:44 UTC
Permalink
oh you are right.. thats certainly the problem and i just realized that on
the development server I'm loading it from the file system.

My URL that I m using for the production server is absolute, it looks like
this:
http://localhost/my_project/media/fonts/<http://localhost/aeon_infrastructure/media/fonts/>
calibri.ttf

Thus I try to load it from the file system. Actually its my first time
deploying a project on an apache server and I'm kind of confused :D
Now I'm wondering where apache is looking after it when I try to get it from
the file system. Obviously apache does not find the file, since I'm getting
a file not found error:

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 ;-)

Thanks guys for the prompt help.. and thanks for this amazing library!!


2010/3/25 Andy Robinson <andy at reportlab.com>
Post by Thomas Kremmel
Post by Thomas Kremmel
Hi,
I m developing a django app using reportlab. Till now I just used the
django
Post by Thomas Kremmel
development server to serve all media files, including some ttf fonts to
be
Post by Thomas Kremmel
pdfmetrics.registerFont(TTFont('Calibri', settings.MEDIA_URL +
'fonts/calibri.ttf'))
That worked fine till I switched from the django development server to
I never even realised we could load fonts from URLs! I guess we're
doing some transformation on the URLs.
Is your production MEDIA_URL relative, or on some other domain
("http://media.mydomain.com/fonts") ?
Also, out of curiosity, if the fonts are on the same box, why don't
you load them from the file system to save all the HTTP negotiation?
- 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/7e650c5c/attachment.htm>
Andy Robinson
2010-03-25 11:53:58 UTC
Permalink
Post by Thomas Kremmel
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
Thomas Kremmel
2010-03-25 12:36:58 UTC
Permalink
Oh yes... that helped! Thank you. That saved my working day ;-)

2010/3/25 Andy Robinson <andy at reportlab.com>
Post by Andy Robinson
Post by Thomas Kremmel
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/575f0be6/attachment-0001.html>
Thomas Kremmel
2010-03-25 12:39:50 UTC
Permalink
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>
Post by Thomas Kremmel
Oh yes... that helped! Thank you. That saved my working day ;-)
2010/3/25 Andy Robinson <andy at reportlab.com>
Post by Andy Robinson
Post by Thomas Kremmel
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>
Tim Roberts
2010-03-25 17:50:50 UTC
Permalink
Post by Thomas Kremmel
Hi,
I m developing a django app using reportlab. Till now I just used the
django development server to serve all media files, including some ttf
pdfmetrics.registerFont(TTFont('Calibri', settings.MEDIA_URL +
'fonts/calibri.ttf'))
That worked fine till I switched from the django development server to
TTFError at /accounting/export/do/
Not a TrueType font: version=0x3C21444F
In ASCII, that hex sequence would be <!DO, which looks very much like
the <!DOCTYPE header you'd get from an HTML page. Is it possible you
downloaded this font improperly?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100325/4e2e834b/attachment.htm>
Loading...