[reportlab-users] TTF-Font Support

Tom Py mailtank2013 at gmail.com
Tue Mar 19 04:29:36 EDT 2013


Hi,

regarding my question at the beginning the Font-Support works for me, but
only when I print out the pdf directly (Font is originally an otf-font,
convertet into afm and pfb-files).

# direct output
def createReport()
....
addFonts = ['FuturaStd-Book', 'FuturaStd-Light']

for font in addFonts:
fontFolder = 'C:\\fonts\\'
afmFile = os.path.join(fontFolder, font + '.afm')
pfbFile = os.path.join(fontFolder, font + '.pfb')
print afmFile, pfbFile
fontFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
fontName = font
pdfmetrics.registerTypeFace(fontFace)
theFont = pdfmetrics.Font(font, fontName, 'WinAnsiEncoding')
pdfmetrics.registerFont(theFont)

.....

canvas.showPage()
return canvas.save()

# create the report
pdfStream = createReport()

But I have first put the pdf into a DB. And from there I give the file to
the user. It works with the reportlab standard fonts (Helvetica), but not
with additional fonts (Futura in my case).

# via DB
def createReport()
....
addFonts = ['FuturaStd-Book', 'FuturaStd-Light']

for font in addFonts:
fontFolder = 'C:\\fonts\\'
afmFile = os.path.join(fontFolder, font + '.afm')
pfbFile = os.path.join(fontFolder, font + '.pfb')
print afmFile, pfbFile
fontFace = pdfmetrics.EmbeddedType1Face(afmFile, pfbFile)
fontName = font
pdfmetrics.registerTypeFace(fontFace)
theFont = pdfmetrics.Font(font, fontName, 'WinAnsiEncoding')
pdfmetrics.registerFont(theFont)

.....
return canvas.getpdfdata()

# create the report
pdfStream = createReport()

# save the report in DB
saveReport(pdfStream):
sqlStatement = """exec storedProcedure @content='%s' """ %
(pdfStream.replace("'","''").replace("\r\n","\n"))
executeNonQuery(sqlStatement)
return

In this case the pdf opens with the error: 'Cannot extract the embedded
font "FuturaStd-Book". Some characters may not display or print correctly.'
(Note: this way works fine with standard fonts, but not with the addidional
font.).


Any idea, why this do not work with the additional font?


Thanks for support, Tom




2013/1/24 Andy Robinson <andy at reportlab.com>


> On 24 January 2013 13:54, Dinu Gherman <gherman at darwin.in-berlin.de>

> wrote:

> > Am 24.01.2013 um 13:27 schrieb Andy Robinson:

> >

> >> Thanks! I have logged it in Dinu's tracker - which is actually quite

> nice.

> >

> > Have you? Once I see it there, I'll mark the day as a holiday in my

> > calendar. ;-)

> >

>

> Hmm. It turns out that unless I sign up, it silently appears to

> accept issues, but they don't show up.

>

> Suggested policy: link to the thread in the email archive.

>

> I just added it using a personal bitbucket account; we'll look into a

> ReportLab one.

>

> - 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/20130319/5cf11615/attachment.htm>


More information about the reportlab-users mailing list