[reportlab-users] BaseDocTemplate && setFont question

Sergey Levchenko sector119 at gmail.com
Mon Apr 4 04:34:12 EDT 2011


Hello.

How can I set default font for entire document?

I try to do it this way, but it doesn't work :/ I got default font
without cyrrilic glyphs support...

class Page(PageTemplate):
def beforeDrawPage(self, canvas, document):
canvas.setFont('FreeSans', 12)

class Doc(BaseDocTemplate):
_invalidInitArgs = ('pageTemplates',)

def build(self, flowables, canvasmaker=canvas.Canvas):
self._calc()
frame = Frame(self.leftMargin, self.bottomMargin, self.width,
self.height, id='Frame')
self.addPageTemplates([Page(id='Page', frames=[frame],
pagesize=self.pagesize)])
BaseDocTemplate.build(self, flowables, canvasmaker=canvasmaker)

pdfmetrics.registerFont(TTFont('FreeSans', 'FreeSans.ttf'))

doc = Doc('sample.pdf', pagesize=A4, rightMargin=1*cm,
leftMargin=1*cm, topMargin=1*cm, bottomMargin=1*cm)

content = []

styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Center', alignment=TA_CENTER))

content.append(Paragraph(u'CYRILLIC STRING HERE', styles['Center']))

doc.build(content)


Thanks.


More information about the reportlab-users mailing list