Bengali text can appear broken in a PDF even when the correct font is installed.
I ran into this distinction while working on Bengali PDF generation in a PHP application. The initial instinct was to investigate font loading, embedding, and CSS. But the deeper issue was text shaping: having the glyphs is not the same as knowing how to arrange them.
This is an important distinction when building document-generation systems for languages that use complex scripts.
1. Unicode support and text shaping are different problems
A font provides glyphs that represent characters. However, complex writing systems often need more than a direct character-to-glyph mapping.
Bengali is a good example.
A rendering engine may need to handle:
- Conjunct consonants.
- Reph and other contextual forms.
- Vowel-sign reordering.
- Below-base and post-base forms.
- Glyph substitution and positioning.
OpenType fonts contain shaping information through tables such as GSUB and GPOS.
The shaping engine uses these rules to transform a sequence of Unicode characters into the correctly substituted and positioned glyphs.
Microsoft's Bengali typography documentation describes these shaping operations in detail:
https://learn.microsoft.com/th-th/typography/script-development/bengali
The practical lesson is simple:
A font can contain the required characters while the rendering engine still fails to display the language correctly.
2. Why installing another font may not fix the PDF
Consider a typical CSS configuration:
@font-face { font-family: "Noto Sans Bengali"; src: url("/fonts/NotoSansBengali-Regular.ttf") format("truetype"); } body { font-family: "Noto Sans Bengali", sans-serif; } This helps the browser or renderer select the intended font.
But it does not guarantee that the PDF engine supports the shaping operations required by Bengali.
There are two different failure categories:
Missing glyphs
- Characters appear as empty boxes.
- Some characters disappear.
- The selected font does not contain the required glyphs.
Incorrect shaping
- Characters are visible but arranged incorrectly.
- Conjuncts do not form as expected.
- Vowel signs or contextual forms appear in the wrong positions.
These problems need different debugging approaches.
Changing the font may solve the first category without solving the second.
A reported Bangla rendering issue in the Dompdf repository illustrates this type of problem:
https://github.com/dompdf/dompdf/issues/2627
The exact behavior still depends on the renderer, version, font, and configuration.
3. Test the rendering engine before changing the application
One mistake in document-generation projects is spending too much time changing application code before isolating the rendering engine.
I would approach the problem in this order.
Step 1: Prepare a representative test document
Do not test with only a simple Bengali sentence.
Include representative text containing:
- Common conjuncts.
- Vowel signs.
- Reph.
- Bengali punctuation.
- Numbers mixed with Bengali text.
- Long paragraphs with line wrapping.
For example:
বাংলা ভাষায় যুক্তাক্ষর পরীক্ষা করুন। ক্ষ, জ্ঞ, শ্র, ক্র, প্র এটি একটি পরীক্ষামূলক PDF document। A renderer that handles simple text correctly may still fail on more complex combinations.
Step 2: Verify the font independently
Check:
- Whether the font contains the required glyphs.
- Whether the font file is accessible.
- Whether the expected font family is actually selected.
- Whether the font license permits embedding and distribution.
Do not assume that declaring @font-face means the font has successfully loaded.
Step 3: Compare HTML output with PDF output
Render the same HTML document in a modern browser and through the PDF engine.
This gives you a useful diagnostic split:
| Result | Likely investigation |
|---|---|
| HTML and PDF both look wrong | Font selection or shaping configuration |
| HTML looks correct, PDF looks wrong | PDF renderer or print pipeline |
| Some Bengali combinations fail | Script-specific shaping support |
| Visual output is correct, copied text is wrong | PDF text encoding or extraction layer |
The browser comparison is particularly useful because Chromium's text-rendering architecture uses HarfBuzz for shaping before drawing glyphs through Skia.
Reference:
https://github.com/chromium/chromium/blob/main/docs/ui/text_rendering/render_text_overview.md
That does not mean every Chromium PDF configuration is automatically perfect. It gives you a different rendering path to evaluate.
4. Why a browser-based PDF pipeline can be a better fit
When the PDF library cannot produce the required shaping, rendering HTML through a browser engine is worth evaluating.
A browser-based approach offers:
- Modern CSS layout.
- Browser font selection and fallback.
- Complex-script text shaping.
- More flexible page styling.
- A familiar HTML-based document template.
For a Laravel application, the architecture can look like this:
Laravel Application | v Prepare document data | v Render HTML template | v Load fonts and CSS | v Browser-based PDF rendering | v Store generated PDF However, this introduces another architectural dependency: the browser runtime.
Before choosing this approach, verify:
- Whether the Chromium binary can be installed.
- Whether the application can launch external processes.
- Whether
proc_openis available when the chosen process runner requires it. - Whether the hosting environment has enough memory.
- Whether execution time limits are suitable.
- Whether the queue or background-processing strategy can handle generation workloads.
A solution that works perfectly on a local development machine may fail on restricted shared hosting.
The renderer is not just a library dependency. It is an infrastructure dependency.
5. Don't forget PDF quality checks
A successful PDF response does not necessarily mean the generated document is correct.
I would validate at least four things:
Visual correctness
Open the PDF and inspect representative Bengali text at different font sizes.
Page layout
Check line wrapping, margins, tables, headers, footers, and page breaks.
Text extraction
Copy Bengali text from the PDF and verify that the extracted content remains meaningful.
Production behavior
Generate documents in the actual deployment environment, not only in local development.
This is especially important when the PDF pipeline depends on an external browser process.
6. The architectural lesson
The most useful lesson from this problem is that document rendering should be evaluated against the languages the application actually supports.
A PDF engine that works perfectly for English invoices may not be suitable for Bengali documents.
Before committing to a rendering library, test:
- The target language.
- The font and its shaping features.
- The rendering engine.
- The final PDF output.
- The production hosting environment.
This avoids building an entire document-generation workflow around a renderer that cannot meet the application's language requirements.
A font provides the glyphs. A shaping engine knows how to arrange them. A reliable PDF pipeline needs both.
References
- Microsoft — Developing OpenType Fonts for Bengali Script
- Chromium — RenderText and HarfBuzz
- Dompdf — Bangla language font break problem
AI disclosure: This article was generated primarily with an AI writing system. It should be reviewed and technically verified by the author before publication.
DEV.to AI disclosure selection: Fully Autonomous.

