[reportlab-users] Changing fonts for a SimpleDocTemplate

Robin Becker robin at reportlab.com
Mon Nov 22 05:40:36 EST 2010


On 20/11/2010 06:43, Thejaswi Puthraya wrote:
...........

> So I was thinking of embedding a custom font. Here's how I am trying it and

> it doesn't seem to work (I am fairly sure I am missing something)

>

> pdfmetrics.registerFont(TTFont('EurostileExtended',

> "/path/to/fonts/EurostileExtended-Roman-DTC.TTF")))

> doct = doctemplate.SimpleDocTemplate("/path/to/output.pdf",

> pagesize=landscape(A4))

> style_sheet = getSampleStyleSheet()

> style_sheet.add(ParagraphStyle(name='TestStyle',

>

> fontName='EurostileExtended',

> fontSize=12,

> leading=12)

> data = []

> data.append((Paragraph(some_content, style=style_sheet["Title"]),

> Paragraph(story_content,

> style=style_sheet["TestStyle"])))

> 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.setTitle("Some title")

> canvas.showPage()

> canvas.save()

.......

OK I was being stupid. You've saved the document in the doct.build command. then
you save it again in the canvas save command. Just remove the lines

> canvas = doct.canv
> canvas.setTitle("Some title")
> canvas.showPage()
> canvas.save()

in the above and it starts to work.
--
Robin Becker


More information about the reportlab-users mailing list