[reportlab-users] Changing fonts for a SimpleDocTemplate
Henning von Bargen
H.vonBargen at t-p.com
Mon Nov 15 03:02:54 EST 2010
IIRC when you are using platypus,
it shouldn't be necessary to call canvas.addFont.
If you want to use that font for your table cells,
just add
style.add(*('FONT', (0,0), (-1,-1), TestFont', 10))
to your code.
Henning
-----Ursprüngliche Nachricht-----
Von: reportlab-users-bounces at lists2.reportlab.com
[mailto:reportlab-users-bounces at lists2.reportlab.com]Im Auftrag von
reportlab-users-request at lists2.reportlab.com
Thejaswi Puthraya wrote:
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.
More information about the reportlab-users
mailing list