Bangla PDF to Word, tested
94.8%
words right at best: the free script
Whole words right, 3 typed PDFs
| Way | Chromium | LibreOffice | reportlab |
|---|---|---|---|
| LibreOffice Writer | 24.1% | 5.4% | 24.2% |
| pdf2docx | 87.2% | 93.7% | 3.5% |
| pdftotext | 80.4% | 80.4% | 27.8% |
| Tesseract: ben (fast) | 81.4% | 86.5% | 86.0% |
| The script: Tesseract ben best | 94.0% | 94.8% | 90.1% |
- pdftotext put a space or a line break inside 1 in 5 words on the good PDFs: প্র থমে for প্রথমে.
- Tesseract wrote 5 of the 13 candrabindu (ঁ). pdf2docx kept them all on the good PDFs.
Why converters break Bangla
- Split words. No copy of the text kept every word whole. PyMuPDF, the library inside pdf2docx, came closest: 977 of 1,042.
- Shapes, not letters. LibreOffice Writer put signs before their letters and split lines into 611 to 910 text boxes.
- Private codes. The reportlab PDF's text holds 900 Private Use Area codes. pdf2docx hit an XML error on all 12 of its pages and kept 3.5% of the words.
The script: OCR every page
Copying the text split words, so the script reads each page with Tesseract ben best and lets pandoc write the .docx.
mkdir best
curl -fL -o best/ben.traineddata https://raw.githubusercontent.com/tesseract-ocr/tessdata_best/4.1.0/ben.traineddata
python3 bangla_pdf_to_word.py in.pdf out.docx best
- It needs Python 3, pandoc, Poppler and Tesseract.
-
Leave out
bestto use the ben you have installed. Homebrew's is the fast one, which read fewer words. - It marks the .docx Bengali (bn-BD), also for complex script, where pandoc leaves Arabic.
- The .docx is plain paragraphs, with no pictures, tables or layout.
bangla_pdf_to_word.py, the whole script
"""Bangla PDF to Word: an editable .docx. The script of brasspage.com/bangla-pdf-to-word/
Needs on your PATH: Poppler (pdftoppm), Tesseract with the ben model, and pandoc. Python 3, stdlib only.
python3 bangla_pdf_to_word.py in.pdf out.docx [tessdata folder]
Every page is read by Tesseract (300 dpi), not copied: on our typed Bangla PDFs the PDF's own text split words
(pdftotext kept about 4 in 5 whole), and an old font such as Bijoy SutonnyMJ stores Latin codes. Give a folder that
holds tessdata_best's ben.traineddata to use that model (it read more words than the fast ben that Homebrew
installs). Blank lines split paragraphs. pandoc writes the .docx in Bengali (bn-BD), and set_bangla() marks it
Bengali for complex script too (bn-BD, not pandoc's ar-SA). Each page goes to stderr as it is read.
"""
import html
import re
import subprocess
import sys
import tempfile
import zipfile
from pathlib import Path
def ocr(png, tessdata):
cmd = ["tesseract", str(png), "-", "-l", "ben", "--dpi", "300"]
if tessdata:
cmd += ["--tessdata-dir", tessdata]
r = subprocess.run(cmd, capture_output=True)
if r.returncode:
sys.exit(r.stderr.decode()) # Tesseract's own error, for example a missing ben model
return r.stdout.decode()
def paragraphs(text):
return [" ".join(b.split()) for b in re.split(r"\n\s*\n", text) if b.strip()]
def pdf_to_docx(pdf, docx, tessdata=None):
paras = []
with tempfile.TemporaryDirectory() as tmp:
subprocess.run(["pdftoppm", "-r", "300", "-gray", "-png", pdf, f"{tmp}/p"], check=True)
for n, png in enumerate(sorted(Path(tmp).glob("p-*.png"), key=lambda p: int(p.stem[2:])), 1):
print(f"page {n}: OCR", file=sys.stderr)
paras += paragraphs(ocr(png, tessdata)) # ponytail: a paragraph across a page break stays two
body = "".join(f"<p>{html.escape(p)}</p>\n" for p in paras)
subprocess.run(["pandoc", "-f", "html", "-o", docx, "-M", "lang=bn-BD"], input=body.encode(), check=True)
set_bangla(docx)
def set_bangla(docx):
"""pandoc's styles keep Arabic as the complex-script language (w:bidi="ar-SA"). Make it Bengali."""
with zipfile.ZipFile(docx) as z:
parts = [(info, z.read(info)) for info in z.infolist()]
with zipfile.ZipFile(docx, "w") as z:
for info, data in parts:
if info.filename == "word/styles.xml":
data = data.replace(b'w:bidi="ar-SA"', b'w:bidi="bn-BD"')
z.writestr(info, data)
if __name__ == "__main__":
if len(sys.argv) < 3:
sys.exit("usage: python3 bangla_pdf_to_word.py in.pdf out.docx [tessdata folder]")
pdf_to_docx(*sys.argv[1:4])
Bijoy to Unicode, offline
Bijoy fonts such as SutonnyMJ draw Bangla on Latin codes. I had no Bijoy file, so 3 free tools wrote codes for our 1,042 words, and 4 read them back.
| Codes by | PyPI bijoy2unicode reads | bijoy-unicode-converter reads | npm bijoy2unicode reads | abdalgolabs reads |
|---|---|---|---|---|
| PyPI bijoy2unicode | 266 | 993 | 1,002 | 945 |
| bijoy-unicode-converter | 990 | 1,041 | 1,007 | 991 |
| abdalgolabs | 980 | 1,029 | 1,013 | 990 |
npm install bijoy-unicode-converter@0.1.2
node --input-type=module -e 'import { ConvertToUnicode } from "bijoy-unicode-converter"; import { readFileSync } from "node:fs"; process.stdout.write(ConvertToUnicode("bijoy", readFileSync(0, "utf8")));' < bijoy.txt > bangla.txt
-
Its README calls
ConvertToUnicode(text). That throws a TypeError: pass"bijoy"first, as above. -
Save bijoy.txt as UTF-8.
pdftotext -enc UTF-8does that.
Where the Bijoy tools disagree
- The reph. A common miss is a র্ on the wrong letter: পরির্বতন for পরিবর্তন. The writers' codes matched on at most 2 of 12 passages.
- A crash. PyPI bijoy2unicode stopped with an IndexError on 9 of its own 12 passages. Each ended in the reph code.
- A skip. abdalgolabs returns text unchanged if it holds any character from the Bengali block. One passage kept ৰ, which no writer coded, so it came back as codes.
- Two code points. Wikisource stores য়, ড় and ঢ় as two code points each. 2 of the 3 writers left all 137 such dots in their codes, so I joined them first.
A look-alike Bijoy PDF
My look-alike PDFs drew each tool's codes in DejaVu Sans: I found no SutonnyMJ font with a license.
pdftotext, then bijoy-unicode-converter: 1,039 words back from its own codes, 1,028 from abdalgolabs codes. abdalgolabs read 1,040 from both.
pdftotext -enc UTF-8 old.pdf bijoy.txt
# then the node line above
pandoc -f markdown bangla.txt -o bangla.docx -M lang=bn
The script OCRs every page, so it never copies the codes. On a real Bijoy PDF, OCR sees the Bangla it draws. I could not test that: my look-alike draws Latin letters.
Our Actor: no install, no Bengali yet
Our Apify Actor, PDF to Markdown OCR, turns PDFs into Markdown in one call. It reads 23 languages, not Bengali yet.
- Runs bill to your Apify account. Your files go to Apify's servers.
What I tested, and what I did not
- No Microsoft Word, and no online converter.
- Typed PDFs only. For scans, see Bengali OCR.
How I tested
- Text: 12 passages from proofread bn.wikisource pages (public domain), one a page. I quote none of them.
- They hold 1,042 words, 308 hasanta and 321 ি signs.
- 3 proofread words hold া then ে in place of ো. OCR wrote ো, so it cannot match them.
- PDFs in Noto Sans Bengali 3.011: Chromium 153 print to PDF and LibreOffice 26.8.1.1 export, both with lang bn, and reportlab 5.1.2 with shaping on.
- Ways: LibreOffice Writer (soffice --infilter=writer_pdf_import), pdf2docx 0.5.13 with PyMuPDF 2.2, pdftotext from Poppler 26.03.0, Tesseract 5.5.4 at 300 dpi with tessdata_fast ben and tessdata_best ben 4.1.0, pandoc 3.13.
- Words right: truth words found whole in the .docx text, each word counted as often as it appears. Text from pdftotext and Tesseract went to pandoc for the .docx.
- I scored the text inside each .docx. LibreOffice on this Mac drew no Bengali when it printed the 4 from the Chromium PDF, so I did not check how they look.
- Bijoy: bijoy2unicode 0.1.1 from PyPI, and from npm bijoy-unicode-converter 0.1.2, bijoy2unicode 1.0.2 (it only reads) and @abdalgolabs/ansi-unicode-converter 1.0.5: the 3 Bijoy tools on npm with the most downloads last month. All ran offline.
- The look-alike PDFs: each writer's codes drawn by reportlab in DejaVu Sans, so they copy like a Bijoy PDF but do not look like one.
- Our Actor has no Bengali model, so it was not in this test.
Sources
- pdf2docx is MIT. It needs PyMuPDF, which is AGPL-3.0 or a paid license.
- bijoy-unicode-converter on npm: MIT, no dependencies.
- bijoy2unicode on PyPI: MIT.
- bijoy2unicode on npm: MIT.
- @abdalgolabs/ansi-unicode-converter on npm: MIT. Its package also holds a web server; I did not run it.
- tessdata_best and tessdata_fast for Tesseract (Apache-2.0).
- Font: Noto Sans Bengali, OFL.
- Scripts and results stay in our private repo, in research/bench/bangla-pdf-to-word-2026-11-28/.
- We make the Apify Actor, not these tools.
Questions people ask
How do I convert a Bangla PDF to Word for free?
OCR each page with Tesseract and the tessdata_best ben model, then let pandoc write the .docx. The free script on this page did that on 3 typed PDFs: 90.1% to 94.8% of words right. Copying the PDF's own text split words.
How do I convert Bijoy (SutonnyMJ) to Unicode?
bijoy-unicode-converter 0.1.2 read back 1,041 of 1,042 words from the Bijoy codes it wrote, and 993 to 1,029 from the other tools' codes, offline. Call ConvertToUnicode("bijoy", text). I had no real Bijoy file, only codes that 3 tools wrote.
Why do Bangla words break when I copy text from a PDF?
pdftotext put spaces and line breaks inside words: it kept 80.4% of words whole on 2 good PDFs. LibreOffice Writer kept 5.4% to 24.2%. OCR of the page image did better.