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.

Metadata

Release files for banglapdf 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for banglapdf 0.2.1
File Size Uploaded Provenance Actions
banglapdf-0.2.1.tar.gz 11.0 kB Without provenance Details for banglapdf-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for banglapdf 0.2.1
File Interpreter ABI Platform Actions
banglapdf-0.2.1-py3-none-any.whl Python 3 none any Details for banglapdf-0.2.1-py3-none-any.whl

Total release size: 20.2 kB

Release files / banglapdf-0.2.1.tar.gz

Download URL banglapdf-0.2.1.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7c527811866d80837c76ce78eb99a1e95329afee8398dbe131b2c1421502c24d
BLAKE2b-256 checksum
How to use checksums
d89e0317d7b863ffac44512cc7883232192ec73a29f537c4a0f247430e83ca73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / banglapdf-0.2.1-py3-none-any.whl

Download URL banglapdf-0.2.1-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
712a5d6a48dee43b060c31c8acd05145a36e34ae483cd070ab8bd15ed93f0d2a
BLAKE2b-256 checksum
How to use checksums
ed10412cb0def17050216df7711b0949e10469345ac516f3be680f5f0e0a52b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for banglapdf 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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