4

I have tried to write Bangla font to create a pdf file using pyfpdf in python. I have written the bangla word using Unicode Avro Bangla Phonetic Font. But when I use pdf.cell command to write the bangla word in the pdf file, the letters in the word gets interchanged. For example, if I try to write the word "করিম", it gets written in the pdf file as "করমি". Here is the code:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font('DejaVu Sans', '', r'C:\Users\PWD-PD-5\Desktop\kalpurush.ttf', uni = True)
pdf.set_font('DejaVu Sans', size = 20)

a = str("করিম") 

pdf.cell (200, 10, '%s'%a, ln=1, align = "C")

pdf.output ("Bangla.pdf")

The Word "করিম" is shown like the picture below, in the output. Please help to solve the problem.

"করিম"

Ishtiaque
  • 41
  • 3
  • Does it help if you use a different font? Does the rendering work correctly with this font in other programs? Is there a difference between Windows, Linux, and Mac environments? I know some text rendering engines have incomplete support for Indic scripts but don't know enough about either to offer any concrete suggestions. – tripleee Aug 30 '20 at 10:24
  • `for c in "করিম": print( c, unicodedata.category(c), unicodedata.name(c))` returns `ি Mc BENGALI VOWEL SIGN I` at the 3rd line. Weird because this _SpacingCombiningMark_ [should stand to the left of the consonant](https://scriptsource.org/char/U0009BF) `র Lo BENGALI LETTER RA` i.e. at the 2nd line? Sorry, I can't help to solve the problem. Fyi, tested using python 3.8.3 in Windows terminal (the same order shows Chrome extension _Unicode Analyzer_). However, if I move that vowel to 2nd position then I get rendered wrong `'কিরম'`… – JosefZ Aug 30 '20 at 10:49
  • ি is a vowel equivalent to an `i` or an `ee`. By natural convention, it follows the consonant. In my phone's bengali keyboard, to get the bangla equivalent রি of the english syllable `ri`, I need to type র follwed by ি. So the problem is that the interpretation is being done in the form of vowel-consonant, where it should really be consonant-vowel. – Mercury Sep 08 '20 at 00:03

0 Answers0