Skip to main content

banglapdf

Correctly shaped Bangla (Bengali) text in ReportLab PDFs.

রিপোর্টল্যাবে বাংলা লিখলে যুক্তাক্ষর ভেঙে যায়, ি-কার ভুল জায়গায় বসে — banglapdf সেই সমস্যার সমাধান।

The problem

Out of the box, ReportLab renders Bangla like this:

বিজ্‌ঞান, স্‌বাস্‌থ্‌য, প্‌রক্‌রিয়া (broken conjuncts, misplaced kars)

Two things are needed to fix it, and both are easy to get wrong:

  1. HarfBuzz shaping must be enabled (shaping=1 on the paragraph style, with uharfbuzz installed) — otherwise conjuncts (ক্ষ, স্থ, দ্ধ) and vowel signs never form.
  2. No inline font switching inside shaped paragraphs. Mixed Bangla+English text ("Python-এর সাথে বাংলা") crashes or garbles if you switch fonts mid-word, because shaping runs per text fragment. The fix is a single font that covers both scripts — banglapdf builds one at runtime by merging Noto Sans (Latin) with Noto Sans Bengali using fontTools, and caches it in ~/.cache/banglapdf/.

banglapdf packages both fixes behind a two-line API.

Install

pip install banglapdf

You also need the Noto fonts (already present on most desktop Linux systems):

sudo apt install fonts-noto-core        # Debian / Ubuntu

Any other Latin+Bangla font pair also works — pass explicit paths to register_fonts().

Choosing a Bangla font family

Three named families are built in:

register_fonts()                        # Noto Sans Bengali (default)
register_fonts(family="solaimanlipi")   # SolaimanLipi
register_fonts(family="lohit")          # Lohit Bengali

For SolaimanLipi, download the font from OmicronLab and copy the .ttf into ~/.local/share/fonts/ — banglapdf will find it there. If a family has no bold variant on your system, the regular weight is reused for bold text (with a warning). For anything else, pass explicit paths:

register_fonts(bangla_regular="/path/to/MyBangla.ttf",
               bangla_bold="/path/to/MyBangla-Bold.ttf")

Quickstart

from reportlab.platypus import SimpleDocTemplate
from banglapdf import register_fonts, BanglaParagraph, bangla_style

register_fonts()   # merge + cache + register fonts (names: "Bangla", "BanglaB")

story = [
    BanglaParagraph("আমার সোনার বাংলা, আমি তোমায় ভালোবাসি",
                    bangla_style(bold=True, fontSize=16)),
    BanglaParagraph("যুক্তাক্ষর (ক্ষ, স্থ, দ্ধ), ি-কার এবং English শব্দ — "
                    "সব একসাথে নিখুঁতভাবে render হয়।"),
]
SimpleDocTemplate("demo.pdf").build(story)

API

Function What it does
register_fonts(regular="Bangla", bold="BanglaB", family="noto", latin_regular=..., bangla_regular=..., ...) Merges a Latin + a Bangla TTF into one font (cached), registers it with ReportLab, and sets up the font family so <b> tags work. family picks a named Bangla family: "noto", "solaimanlipi" or "lohit".
bangla_style(name, bold=False, **ParagraphStyle_kwargs) A ParagraphStyle with the merged font and shaping=1 preset.
BanglaParagraph(text, style=None, markup=False, **style_overrides) A Paragraph that escapes markup characters by default; pass markup=True to use ReportLab inline tags yourself.
merged_font_path(weight, latin, bangla, force=False) Path to the cached merged TTF (builds it on first call).
escape(text) Escapes &, <, > for paragraph markup.

Everything else is plain ReportLab — tables, frames, doc templates and canvas drawing all work unchanged; just use the "Bangla"/"BanglaB" font names and shaping=1 (which bangla_style already sets).

Requirements

  • Python ≥ 3.9
  • reportlab ≥ 4.1 (HarfBuzz shaping support)
  • uharfbuzz, fonttools (installed automatically)
  • A Latin and a Bangla TTF on the system (Noto recommended)

License

MIT © MD. MAHBUB ALOM

The Noto fonts used at runtime are licensed under the SIL Open Font License; this package does not redistribute them — it merges the copies already installed on your system.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

banglapdf-0.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

banglapdf-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file banglapdf-0.2.0.tar.gz.

File metadata

  • Download URL: banglapdf-0.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for banglapdf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 773b103e9e1fee57a91a8f7c544c8a37426f0ce0134cc0c342a77db66f67a00a
MD5 9ad6e4c45be5cee27e9fc37ed5e2a950
BLAKE2b-256 aade8d8afad0aeebfc8dd15e55e8c51d53dc8fe05494f7abea123a626b08a310

See more details on using hashes here.

File details

Details for the file banglapdf-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: banglapdf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for banglapdf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcaaded046693e44d76b059b84e7f0b0acbd3c7368f686c565db846e12ec605e
MD5 602cd64e3f4f04192ad8b5542b277fd9
BLAKE2b-256 ea10df712d34cab5b8957c9b4d5aab1e22d30744d84845b0bdc9edec47b84c1c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page