2

I am trying to render Telugu text into pdf using pyfpdf. The problem is with font rendition in fpdf. What might be the problem? The code I used is :

#!/usr/bin/python
# -*- coding: utf8 -*-
from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font('lakkireddy', '', 'LakkiReddy.ttf', uni=True)
pdf.set_font('lakkireddy','', 16)
pdf.cell(40,10,u'హలో ప్రపంచమా!')
pdf.output('testfpdf.pdf','F')`

The expected output is : enter image description here

But the actual output is broken text : enter image description here

What could be the issue, Is it the font, Is it encoding or Is it font rendering engine? Can I define which font rendering engine to use?

ilja
  • 2,592
  • 2
  • 16
  • 23
tuxnani
  • 3,634
  • 6
  • 21
  • 33
  • Are you sure that the font you are trying to use supports font size 16? What happens if you try it with a smaller font size like 12? – Dave Jun 18 '19 at 11:37
  • ఏమైనా సమాధానం దొరికిందా? did you find any solution? – dejjub-AIS Oct 07 '21 at 06:04
  • May be this is related. Surely we need to pass special instructions for processing composite unicode text. https://stackoverflow.com/questions/21188046/writing-hindi-fonts-with-gd-library-do-not-render-as-desired – dejjub-AIS Oct 07 '21 at 06:24

1 Answers1

1

I am not familiar with fpdf but it seems that fpdf does not support proper text shaping for complex scripts. Glyph shapes change based on glyph position in the string and based on its neighbor glyphs but fpdf does not seem to do this kind of processing by default.

You have to check if there are options in fpdf for specifying this kind of processing for complex scripts.

Mihai Iancu
  • 1,818
  • 2
  • 11
  • 10
  • +1 I was facing similar issue in matplotlib and I was certainly sure the renderer is not considering the neighbouring letters. The technical name "Glyph" is going to find me a solution. – dejjub-AIS Oct 07 '21 at 06:11