I am trying to generate pdf using reportlab, with malayalam text(an Indian language).
My code:
# -*- coding: utf-8 -*-
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.cidfonts import CIDFont
import reportlab.rl_config
reportlab.rl_config.warnOnMissingFontGlyphs = 1
v1 = u'മൊബൈലും കേബിളും'
v2 = v1.encode('utf-8').decode('utf-8')
pdfmetrics.registerFont(TTFont('Malayalam', 'Meera.ttf', 'UTF-8'))
c = canvas.Canvas("reportlab-malayalam.pdf")
c.setFont('Malayalam', 14)
c.setAuthor("Sree")
c.setTitle("Reportlab Malayalam")
c.drawString(10,800, str(v2))
c.save()
Output is attached in figureenter image description here:
- There is a square appearing in text.
- The character parts (for malayalam character ബൈ) is appearing in different order in text.
I have tried with different fonts like noto sans malayalam, but result is same.
I was expecting the display to be proper, as when this text is copied into notepad++, it is displaying properly. So as in google docs.
I had referred other questions here but didn't get further clue than what I did.
Am I doing some mistake here?
Edit:
It seems the problem is with combining characters:
From the output, it is evident that the combining characters are displayed as it is, instead of display them combined with previous character.
Support for combining characters was not available with reportlab as suggested by the discussion https://groups.google.com/g/reportlab-users/c/scxAhaReanI.
Is this support available as of now?
If not, any alternate python package has this support?