[reportlab-users] once again with external fonts in pythonpoint
Robin Becker
robin at reportlab.com
Thu Apr 17 10:29:41 EDT 2008
Paul Okop wrote:
>
>> Paul Okop wrote:
>>> Here is the problem:
>>> I've got an XML with unicode-strings(in Cyrillic), need to create PDF out of this with uni-font build-in. Since there is no unicode font in reportlab, I want to use some external font(T1 font called CyrveticaExtra). Is there any algorithm for building the font in the pythonpoint or reportlab?
>>> Editing the stylesheets is not helpfull - fonts.py raises ValueError:
>>>
>>> File "fonts.py", line 68, in ps2tt
>>> ValueError: Can't map determine family/bold/italic for cyrveticaextra
>>>
>>> If got my font copied into 'fonts' folder, then tried to 'insert' font's map into fonts.py - didn't help - pdfmetrics.py raised error:
>>>
>>> File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfmetrics.py", line 617, in getTypeFace
>>> return _typefaces[faceName]
>>> KeyError: 'cyrveticaextra'
>>>
>>> What next? As I understand the brute search should be done and the font should be registered, but the script only raises this error.
>>>
>>>
>>> My system(if needed): Ubuntu 7.10 Python 2.5 Reportlab 2.1
>>> _________
>>> Paul Okop
>> .........
>> We attempt to locate fonts based on the T1SearchPath in rl_config.py. Before you
>> even start with your python point you should try the following.
>>
>> 1) test this simple script
>>
>> from reportlab.pdfgen.canvas import Canvas
>> c = Canvas('tlerc.pdf')
>> c.setFont('LettErrorRobot-Chrome', 12)
>> c.drawString(72,72,'Hello World')
>> c.showPage()
>> c.save()
>>
>> 2) copy the afm files from your fonts to reportlab/fonts
>> 3) change the name LettErrorRobot-Chrome in the above to one of the names in the
>> afm file(s)
>> 4) retry and see if reportlab finds your file.
>> --
>> Robin Becker
>>
>>
>
> This script works well, I've tested it before. Reportlab finds the file(there were no search-errors in log above), reportlab makes a PDF but this PDF rather simple(or should I write a big script for creating reports of 10+ pages with tables and graphics) and this pdf has no font in it.
> As I wrote I need to use pythonpoint, to convert XML to PDF, not just creating PDF from code, but converting a large report XML to PDF with my font build in it. Is there any way to do that?
>
> Ok, I guess there is some misunderstanding. Here is the promblem to solve:
> - I've got an XML file to convert
> - I've got T1 font
> - I've got pythonpoint
>
> What should I do to get a PDF based on my XML with my font in it?
As I suggested right at the outset you need to make up your own stylesheet
following the model in say standard.py
I did the following
1) copy standard.py to madness.py in the styles subfolder
2) edit styles/madness.py
replaced all instances of Times-Roman with LettErrorRobot-Chrome
added some registration stuff at the beginning of the function
def getParagraphStyles():
"""Returns a dictionary of styles to get you started.
We will provide a way to specify a module of these. Note that
this just includes TableStyles as well as ParagraphStyles for any
tables you wish to use.
"""
# this is added
from reportlab.pdfbase import pdfmetrics
pdfmetrics.findFontAndRegister('LettErrorRobot-Chrome')
pdfmetrics.registerFontFamily('LettErrorRobot-Chrome')
################
stylesheet = {}
ParagraphStyle = styles.ParagraphStyle
para = ParagraphStyle('Normal', None) #the ancestor of all
para.fontName = 'LettErrorRobot-Chrome'
3) copy pythonpoint.xml to madpythonpoint.xml
4) changed standard in the <stylesheet tag to be madness in madpythonpoint.xml
5) run pythonpoint.py on the madpythonpoint.xml
6) open madpythonpoint.pdf and admire my foolishness
--
Robin Becker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: madness.zip
Type: application/x-zip-compressed
Size: 8472 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20080417/e1d7f9d4/attachment-0001.bin>
More information about the reportlab-users
mailing list