How to show Asian Bengali font in report lab?

150 views Asked by At

I am going to generate a pdf by report lab using Asian 'Bengali Font' but give me a blank page. Is there any way to show the 'Bengali Font' in report lab properly?

I try so many ways to solve my problem according to online guides but not solved my problem.

Like I expect 'আমার সোনার বাংলা' but after making pdf the page is blank.

Here is my code snipped.

from reportlab import rl_config
from reportlab.pdfbase.ttfonts import TTFont 
from reportlab.pdfbase.pdfmetrics import registerFont
registerFont(TTFont('bangla', 'SutonnyMJ-Regular.ttf'))
rl_config._SAVED['canvas_basefontname'] = 'bangla'
rl_config._startUp()

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import landscape, A4
from reportlab.platypus import Paragraph
from reportlab.lib.styles import ParagraphStyle


my_Style=ParagraphStyle('My Para style', fontName='bangla', fontSize=16,borderWidtenter code hereh=2,borderPadding=(20,20,20),leading=20,alignment=0)

width,height=A4
my_path='hello.pdf' 
c = canvas.Canvas(my_path, pagesize=A4)

p1=Paragraph('''আমার সোনার বাংলা''',my_Style)

p1.wrapOn(c,300,50)
p1.drawOn(c,width-450,height-350)
c.save()
1

There are 1 answers

0
Maktum On

Now I got the answer after hours of hours research by this GitHub repo.

https://github.com/MS-Jahan/unicode2bijoy

  1. Change the text Unicode to Bijoy by this repo.
  2. Draw the Bijoy text on canvas. Thats it.