[reportlab-users] Changing fonts for a SimpleDocTemplate

Thejaswi Puthraya thejaswi.puthraya at gmail.com
Sun Nov 14 11:52:24 EST 2010


I have a simple doc template with two flowables, a paragraph and a long
table. The PDFs get generated fine but I want to customize the fonts
(preferably embed them) that are used to display the document. How do I go
about this task?

Here is a simple snippet of my code below for context:

pdfmetrics.registerFont(TTFont('TestFont', "/path/to/fonts/test_font.ttf")))
doct = doctemplate.SimpleDocTemplate('test.pdf',
pagesize=landscape(A4))
# data is a list of lists
data = [...]
style_sheet = getSampleStyleSheet()
style = GRID_STYLE
style.add(*('VALIGN', (0,0), (-1,-1), 'MIDDLE'))
style.add(*('LEFTPADDING', (0,0), (-1,-1), 15))
style.add(*('RIGHTPADDING', (0,0), (-1,-1), 15))
table = LongTable(data, colWidths=360, rowHeights=215, style=style)
page_flowables = [table]
doct.build(page_flowables)
canvas = doct.canv
# canvas.addFont('TestFont')
canvas.setTitle("Some title")
canvas.showPage()
canvas.save()

We get hold of the canvas object only after the flowables have been built.
Should the font be changed after building the doc or before and if one of
these, how?

Btw, the addFont method on the canvas doesn't work because there is no
'addFont' method defined on the PDFDocument class, so there is an error
raised every time addFont is called on the canvas instance. I don't seem to
be alone in facing these problem [1].

I wanted to raise a ticket for the above problem but couldn't locate a
ticket tracker.

[1]
http://stackoverflow.com/questions/2656145/adding-a-font-for-use-in-reportlab

--
Cheers
Theju
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20101114/811a45b8/attachment.html>


More information about the reportlab-users mailing list