Kannada PDF to Word, tested
100%
words right, 2 of 3 PDFs: the script
Whole words right, 3 typed PDFs
| Way | Chromium | LibreOffice | reportlab |
|---|---|---|---|
| LibreOffice Writer | 11.2% | 2.9% | 10.9% |
| pdf2docx | 74.9% | 91.5% | 10.0% |
| pdftotext | 99.7% | 99.7% | 10.9% |
| Tesseract: kan (fast) | 97.6% | 96.9% | 97.1% |
| The script: text, OCR if broken | 100.0% | 100.0% | 98.6% |
- pdftotext kept all 717 words on the good PDFs. pandoc then lost 2: it read a * as italics.
- Tesseract wrote 12 zero width non-joiners where the text has 1, as after ಉಮರ್. Those words no longer match.
Why converters break Kannada
- Shapes, not letters. LibreOffice Writer put vowel signs before their letters and split lines into 108 to 246 text boxes.
- A weak copy. pdf2docx reads text with PyMuPDF, whose plain copy kept 474 and 649 of 717 words on the good PDFs.
- Private codes. The reportlab PDF's text holds 1,478 Private Use Area codes. pdf2docx also skipped its page 9 with an XML error.
The script: text first, OCR if broken
The script keeps a good PDF's own text and sends a broken page to Tesseract kan.
python3 kannada_pdf_to_word.py in.pdf out.docx
- It needs Python 3, pandoc, Poppler and Tesseract with kan.
- Broken means under 20 Kannada letters (a scan, a Nudi or English page), Private Use Area or NUL codes, or 3 or more stray signs.
- It deletes Tesseract's stray non-joiners at a word end.
- Homebrew's fast kan read as many words as kan best, or more.
- It marks the .docx Kannada (kn-IN) for complex script too, not pandoc's Arabic.
kannada_pdf_to_word.py, the whole script
"""Kannada PDF to Word: an editable .docx. The script of brasspage.com/kannada-pdf-to-word/
Needs on your PATH: Poppler (pdftotext, pdftoppm), Tesseract with the kan model, and pandoc. Python 3, stdlib only.
python3 kannada_pdf_to_word.py in.pdf out.docx [tessdata folder]
Each page: the PDF's own text (pdftotext). A page whose own text is broken is read by Tesseract (300 dpi) instead.
Broken: fewer than 20 Kannada letters (a scan, or an old font such as Nudi or Baraha that stores Latin codes),
Private Use Area characters, NUL characters, or 3 or more vowel signs or viramas that do not follow a consonant.
Give a tessdata folder that holds kan.traineddata if your Tesseract has no kan. Tesseract writes a zero width
non-joiner (U+200C) after a virama at the end of a word; the script deletes those, so a search for the word
finds it, and keeps the ones inside a word. Blank lines split paragraphs. pandoc writes the .docx in Kannada (kn-IN),
and set_kannada() marks it Kannada for complex script too (kn-IN, not pandoc's ar-SA). Each page's choice goes to
stderr.
"""
import html
import re
import subprocess
import sys
import unicodedata
import zipfile
KANNADA = re.compile("[\u0c80-\u0ce3\u0cf1-\u0cf3]") # Kannada letters and signs
ORPHAN = re.compile("(?<![\u0c95-\u0cb9\u0cbc\u0cdd\u0cde])[\u0cbe-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3]") # a sign not after a consonant
END_ZWNJ = re.compile("\u200c(?![\u0c80-\u0cf3])") # a zero width non-joiner with no Kannada letter after it
def broken(text):
"""Why a page's own text is broken, or None if it looks right."""
t = unicodedata.normalize("NFC", text).translate({0x200C: None, 0x200D: None})
if len(KANNADA.findall(t)) < 20: # ponytail: an English-only page goes to OCR too
return "no Kannada text"
if re.search("[\ue000-\uf8ff]", t):
return "Private Use Area characters"
if "\x00" in t:
return "NUL characters"
if len(ORPHAN.findall(t)) >= 3: # one stray sign is a typing slip, not a broken page
return "vowel signs or viramas not after a letter"
return None
def ocr(pdf, n, tessdata):
page = ["pdftoppm", "-r", "300", "-gray", "-png", "-f", str(n), "-l", str(n), pdf]
png = subprocess.run(page, capture_output=True, check=True).stdout
cmd = ["tesseract", "-", "-", "-l", "kan", "--dpi", "300"]
if tessdata:
cmd += ["--tessdata-dir", tessdata]
r = subprocess.run(cmd, input=png, capture_output=True)
if r.returncode:
sys.exit(r.stderr.decode()) # Tesseract's own error, for example a missing kan model
return END_ZWNJ.sub("", 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):
out = subprocess.run(["pdftotext", "-enc", "UTF-8", pdf, "-"], capture_output=True, check=True).stdout.decode()
paras = []
for n, text in enumerate(out.split("\f")[:-1], 1): # pdftotext ends every page with a form feed
why = broken(text)
print(f"page {n}: " + (f"OCR ({why})" if why else "text layer"), file=sys.stderr)
paras += paragraphs(ocr(pdf, n, tessdata) if why else text) # 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=kn-IN"], input=body.encode(), check=True)
set_kannada(docx)
def set_kannada(docx):
"""pandoc's styles keep Arabic as the complex-script language (w:bidi="ar-SA"). Make it Kannada."""
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="kn-IN"')
z.writestr(info, data)
if __name__ == "__main__":
if len(sys.argv) < 3:
sys.exit("usage: python3 kannada_pdf_to_word.py in.pdf out.docx [tessdata folder]")
pdf_to_docx(*sys.argv[1:4])
Nudi and Baraha to Unicode, offline
Old Nudi and Baraha BRH fonts draw Kannada on Latin codes, mostly from one table. I had no Nudi file, so 3 free tools wrote codes for our 717 words, and 5 read them back.
| Codes by | kannada-ascii-unicode | Sanka | looped-labs | knconverter | kle.py |
|---|---|---|---|---|---|
| kannada-ascii-unicode | 684 | 558 | 645 | 562 | 570 |
| Sanka | 648 | 711 | 585 | 693 | 677 |
| Sanka, ಷ as B5 | 649 | 711 | 598 | 714 | 698 |
| looped-labs | 130 | 135 | 127 | 141 | 141 |
Convert Nudi text with knconverter
curl -fLO https://raw.githubusercontent.com/aravindavk/ascii2unicode/6d53b9bae48c089bb9e5776b01c55b505005841f/knconverter
pdftotext -enc UTF-8 old.pdf - | iconv -c -f UTF-8 -t CP1252 | python3 knconverter > kannada.txt
pandoc -f markdown kannada.txt -o kannada.docx -M lang=kn
-
knconverter reads CP1252 bytes, not UTF-8, so iconv comes first. Its
-cdrops what CP1252 cannot hold. - On my look-alike PDF of the B5 codes, kannada.txt held 714 of 717 words. The .docx held 712: the same * again.
Where the Nudi tools disagree
- ಷ in Greek. Sanka writes ಷ as the Greek letter μ. The Nudi table, kannada-ascii-unicode and knconverter use byte B5, the micro sign µ.
- Signs left as Unicode. kannada-ascii-unicode left 147 Kannada vowel signs and 31 Kannada digits in its codes.
- A crash. The looped-labs writer threw a StringIndexOutOfBoundsException on 9 of the 12 passages. Its reader wrote ಮನಸುಸು for ಮನಸ್ಸು.
- English. In Nudi, Latin letters are Kannada codes. The readers gave back at most 10 of the 25 letters of one English name.
A look-alike Nudi PDF
My look-alike PDFs drew each tool's codes in DejaVu Sans. KGP's free Nudi fonts and Baraha's paid ones name no license that I found.
pdftotext copied 0 Kannada words from them. The script sent every page of them to OCR. A real Nudi PDF shows Kannada to OCR, but mine draws Latin letters, so I could not test that.
Our Actor: no install, no Kannada yet
Our Apify Actor, PDF to Markdown OCR, turns PDFs into Markdown in one call. It reads 23 languages, not Kannada 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, no online converter, no real Nudi file.
- Typed PDFs only. For scans, see Kannada OCR.
How I tested
- Text: 12 passages from proofread kn.wikisource pages, one a page. 9 are public domain and 3 are CC BY-SA 4.0. I quote no passage, only single words.
- They hold 717 words, 418 viramas and 378 ಿ signs.
- PDFs in Noto Sans Kannada 2.006: Chromium 153 print to PDF and LibreOffice 26.8.1.1 export, both with lang kn, 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 kan and tessdata_best kan 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 Kannada when it printed the 4 .docx files made from the Chromium PDF, so I did not check how they look.
- Nudi writers: kannada-ascii-unicode 0.1.5 from PyPI, Sanka and looped-labs. Readers: those 3, knconverter and kle.py. All ran offline, from pinned versions.
- The look-alike PDFs: each writer's codes drawn by reportlab in DejaVu Sans, so they copy back the codes, but do not look like a Nudi PDF.
- Our Actor has no Kannada model, so it was not in this test.
Sources
- pdf2docx is MIT. It needs PyMuPDF, which is AGPL-3.0 or a paid license.
- ascii2unicode (knconverter): GPL-3.0 or later.
- Sanka: MIT.
- kannada-ascii-unicode on PyPI: MIT.
- looped-labs unicode2asciikannada and asciikannada2unicode: MIT.
- legacy-encodings (kle.py and the Nudi table): MIT or Apache-2.0.
- Kannada Ganaka Parishat makes Nudi and lists it as free, with no license name.
- tessdata_best and tessdata_fast for Tesseract (Apache-2.0).
- Font: Noto Sans Kannada, OFL.
- Scripts and results stay in our private repo, in research/bench/kannada-pdf-to-word-2026-11-28/.
- We make the Apify Actor, not these tools.
Questions people ask
How do I convert a Kannada PDF to Word for free?
Keep the PDF's own text where it is right, and OCR the other pages with Tesseract kan. The free script on this page does both, then pandoc writes the .docx: 717 of 717 words on 2 typed PDFs.
How do I convert Nudi or Baraha text to Unicode?
Give aravindavk's knconverter the text as CP1252 bytes. It read back 714 of 717 words from Sanka's codes with ಷ as byte B5, offline. I had no real Nudi file, only codes that 3 tools wrote.
Why does text from a Nudi PDF come out as Latin letters?
Old Nudi and Baraha BRH fonts draw Kannada letters on Latin codes, so a copy gives you the codes: PÀÄ for ಕು. Convert the codes, or OCR the page.