[reportlab-users] Changing fonts for a SimpleDocTemplate

Thejaswi Puthraya thejaswi.puthraya at gmail.com
Sat Nov 20 01:43:18 EST 2010


Hi,
Sorry for getting back late. Thanks for the answer but probably it's better
to add a little more context to my question...

On Mon, Nov 15, 2010 at 10:30 PM, <
reportlab-users-request at lists2.reportlab.com> wrote:


>

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

>


The main problem, I currently face is that the Helvetica font on Windows
doesn't display some diacritics for European languages like Slovak. It
replaces the glyph with a box. This problem cannot be reproduced on a linux
based operating system. I am calling reportlab from within a web
application.

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()

On running this piece of code, I get the following error:

redefining named object: 'toUnicodeCMap:AAAAAA+EurostileExtended-Roman-DTC'

I am not sure I understand this error and how I am redefining this object
when I am calling registerFont only once.

PS: The addFont method not working has still not been answered ;-)



>

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

>

>

> ------------------------------

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

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

>

>

> End of reportlab-users Digest, Vol 79, Issue 7

> **********************************************

>




--
Cheers
Thejaswi Puthraya
http://thejaswi.info/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20101120/23b12cbc/attachment.html>


More information about the reportlab-users mailing list