Embedding a Bengali Unicode font in a PDF is not enough. Conjuncts and dependent vowel marks need OpenType GSUB/GPOS shaping. If you skip that step, the glyphs look wrong, and search or copy often break because the visual run no longer matches the logical Unicode.
bengali_pdf is a Flutter library I built for that gap. It is a substantially reworked fork of zamansheikh/bangla_pdf, and the original copyright is kept. It shapes each run with HarfBuzz using the same font face that is embedded, paints the returned glyph IDs and positions into a Type 0 PDF font, and places an invisible logical Unicode layer on top so viewers can select, copy, search, and highlight.
What 0.1.0 actually covers
- Native platforms only: Android, iOS, Linux, macOS, and Windows, through
package:harfbuzz_ffi. - Web is deliberately out of this release. There is no equivalent WebAssembly shaping backend in this version, and I will not claim web support.
- Bundled Noto Sans Bengali (OFL-1.1), usable offline. You can also load another legally embeddable TTF/OTF.
- Cluster-safe wrapping that is not supposed to split Bengali conjuncts or combining marks.
- License: BSD-3-Clause.
Update (3 Dec 2026): bengali_pdf is now on pub.dev under the jehadurre.me verified publisher: https://pub.dev/packages/bengali_pdf (latest 0.1.1). It is still native-only; web is out of this release.
dependencies:
bengali_pdf: ^0.1.1
The API, from the README
import 'package:bengali_pdf/bengali_pdf.dart';
import 'package:pdf/widgets.dart' as pw;
final registry = BengaliFontRegistry();
final noto = await BundledBengaliFonts.loadNotoSansBengali(
registry: registry,
);
final text = BengaliPdfTextBuilder(font: noto);
final bengali = await text.build('বাংলাদেশ — মূল্য ৳৫০০।', fontSize: 16);
final document = pw.Document();
document.addPage(
pw.Page(
build: (_) => pw.Row(
children: [pw.Text('Hello '), bengali],
),
),
);
final bytes = await document.save();
The example string is taken from the public README. I am not inventing a generated-PDF screenshot here.
If you generate Bengali PDFs in Flutter on mobile or desktop, the repo is here: https://github.com/JehadurRE/bengali_pdf
Top comments (4)
good that you kept the invisible logical layer, that's the part most people skip. one thing worth testing is the pre-base vowel signs like ি and ে, visually they sit before the consonant but in unicode they come after, so a copy test with কি and কে is a quick way to see if your layer order is right. also reph (র্ক) and ক্ষ, try searching them in chrome's viewer and in pdf.js because both treat the text layer a bit differently. did you check ZWNJ cases too?
Thanks for pushing on this. I tested it properly instead of answering from memory, and it was worth it: main had real bugs.
I made a PDF with কি কে কো, ক্ষ, র্ক কর্ম ধর্ম সূর্য কার্তিক, র্য vs র্য, ক্ষ and a normal sentence. Then I checked copy and search in three engines: pdf.js 6.5 (the text layer plus the viewer's find controller), PDFium (the engine behind Chrome's viewer, run headless through pypdfium2), and Poppler 25.03.
What I found on main:
The fix: each cluster now gets an invisible anchor that carries its Unicode in logical order and its exact shaped width. The visible glyphs sit at their real HarfBuzz positions with zero width, and a stand-alone ZWNJ joins the cluster before it. Now all three engines return the exact source text, and every line and word is searchable, including র্ক, ক্ষ and ক্ষ (and ক্ষ no longer matches ক্ষ). CI now checks Poppler, PDFium and pdf.js on every push. The fix is merged: github.com/JehadurRE/bengali_pdf/p...
One pdf.js quirk worth knowing: with "Match Diacritics" off, which is Firefox's default, pdf.js strips vowel signs before matching, so searching কি also hits every ক. That happens with any Bengali PDF. Turning Match Diacritics on gives exact matches.
Not tested yet: clicking through Chrome's actual UI (I used the same PDFium engine headless) and Acrobat.
wow thanks for actually running all that, didnt expect this much. the match diacritics thing is good to know, i would have blamed the pdf for sure. for the not tested part, also try copy from the PDF and paste into notepad or whatsapp, thats what most normal users do and sometimes it breaks even when search works
Good point — copy from the PDF and paste into a plain-text app is what most people actually do, and I didn't test that path. I'll add "copy → paste into Notepad / a chat app" for কি, কে, ক্ষ and র্ক to the manual checklist next to the search tests. Thanks again for the careful review.