Tools,

Kannada PDF to Word, tested

100%

words right, 2 of 3 PDFs: the script

Get the free script

Whole words right, 3 typed PDFs

Way Chromium Libre­Office 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%

Why converters break Kannada

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
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.

Words back, of 717: rows wrote, columns read
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

Where the Nudi tools disagree

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.

What I tested, and what I did not

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

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.