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:
- HarfBuzz shaping must be enabled (
shaping=1on the paragraph style, withuharfbuzzinstalled) — otherwise conjuncts (ক্ষ, স্থ, দ্ধ) and vowel signs never form. - 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 —
banglapdfbuilds 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file banglapdf-0.2.1.tar.gz.
File metadata
- Download URL: banglapdf-0.2.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c527811866d80837c76ce78eb99a1e95329afee8398dbe131b2c1421502c24d
|
|
| MD5 |
ae8729160b52b7a3b25972395a2c6ad7
|
|
| BLAKE2b-256 |
d89e0317d7b863ffac44512cc7883232192ec73a29f537c4a0f247430e83ca73
|
File details
Details for the file banglapdf-0.2.1-py3-none-any.whl.
File metadata
- Download URL: banglapdf-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
712a5d6a48dee43b060c31c8acd05145a36e34ae483cd070ab8bd15ed93f0d2a
|
|
| MD5 |
2100c2ff83f969884553432ce7a1af5a
|
|
| BLAKE2b-256 |
ed10412cb0def17050216df7711b0949e10469345ac516f3be680f5f0e0a52b7
|