is there any option to convert latin2 letters in a proper way? I need polish letter to my school project. Here is some code how I generate pdf
#!/usr/bin/python
# -*- utf-8 -*-
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, A4
def GenerujPustyArkusz(c):
c.setFont("Times-Roman", 8)
c.drawString(450,750, u"Załącznik nr 2 do Regulaminu")
def test():
c = canvas.Canvas("test.pdf", pagesize=letter)
GenerujPustyArkusz(c)
c.showPage()
c.save()
test()
And I get this:
Za■■cznik nr 2 do Regulaminu
I tried several encoding tricks with no result.
I think the main problem is that the font you're using doesn't have those polish characters. This code worked for me and showed up the characters you wanted:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
def GenerujPustyArkusz(c):
pdfmetrics.registerFont(TTFont('Verdana', 'Verdana.ttf'))
c.setFont("Verdana", 8)
s = u"Załącznik nr 2 do Regulaminu"
c.drawString(450,750, s)
def test():
c = canvas.Canvas("test.pdf", pagesize=letter)
GenerujPustyArkusz(c)
c.showPage()
c.save()
test()
If you want to use other font you'll have to find the typeface you want that include the polish characters.
I hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With