[reportlab-users] BaseDocTemplate && setFont question

Michael Dorrian michael.dorrian at gmail.com
Mon Apr 4 04:48:26 EDT 2011


pdfmetrics.registerFont(FontName)

Sent from my iPod

On 2011/04/04, at 17:34, Sergey Levchenko <sector119 at gmail.com> wrote:


> 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.

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users



More information about the reportlab-users mailing list