[reportlab-users] Embedded font problems

Tim Roberts timr at probo.com
Mon Mar 13 12:14:49 EDT 2017


jsmith4332--- via reportlab-users wrote:
>
> Does anyone have troubleshooting tips for figuring out why an embedded
> TTF font does not work in reportlab (just shows rectangles)? I'm
> trying to
> use https://grandzebu.net/informatique/codbar/code128.ttf (yes, I
> would like to use a barcode font instead of the built in barcode
> generator due to quality issues when printing on a low DPI printer)

Odd.  I just tried this, and it worked perfectly:

    from reportlab.pdfgen import canvas
    from reportlab.lib.pagesizes import LETTER
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont

    pdfmetrics.registerFont( TTFont( 'code128', '/tmp/code128.ttf'))

    canv = canvas.Canvas( 'code.pdf', pagesize=LETTER )
    canv.setPageCompression( 0 )
    canv.setFont( 'code128', 14 )
    canv.drawString( 100, 100, "0123456789" )
    canv.showPage()
    canv.save()

Does it work for you?

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20170313/51995970/attachment.html>


More information about the reportlab-users mailing list