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().

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", 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.
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.1.0.tar.gz (7.8 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.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for banglapdf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 37bcdd5e6dce3fa6511227aa7e51c536bea00d4a5e903b1b2c98bb41ad8b4fef
MD5 f84f55c637618860824effffe0ee9c4a
BLAKE2b-256 e4c93ce698d29fbdcd57d61ea874151124ec0dc0fdcfcf9f429085aaf3effa2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: banglapdf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bd833d1b839303f17f6c45c8239918a3205d421203169cda8b11ee721c96c88
MD5 e447a02aa5d340e03a166917e974a277
BLAKE2b-256 8655315afda5c43f63330825d33fe3f5b6785e78084a2d3d7f194486d8197a10

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

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