Tamil PDF to Word, tested
693 of 693
words right on 2 of 3 PDFs: the script
Whole words right, 3 typed PDFs
| Way | Chromium | LibreOffice | reportlab |
|---|---|---|---|
| LibreOffice Writer | 2.3% | 0.1% | 2.3% |
| pdf2docx | 85.9% | 80.4% | 2.2% |
| pdftotext | 100.0% | 100.0% | 2.3% |
| Tesseract: tam | 49.9% | 49.9% | 49.8% |
| Tesseract: tam, U+200C deleted | 99.9% | 99.6% | 99.3% |
| Tesseract: Tamil best, U+200C deleted | 99.6% | 98.8% | 99.3% |
| The script on this page | 100.0% | 100.0% | 99.3% |
- Tesseract wrote U+200C after the pulli 346 or 347 times a PDF. The proofread text has none, so half the words did not match whole.
- pdf2docx dropped the space at many line ends of the Chromium PDF, so two words came out as one. On the LibreOffice PDF it split words into pieces.
Why converters break Tamil
- Shapes, not letters. LibreOffice Writer put signs and letters out of order (குண்ம for குணம்) and split lines into text boxes.
- Private codes. The reportlab PDF's text holds 1,615 Private Use Area codes and not one pulli. Every way that copies its text failed.
The script: text first, OCR if broken
It copies each page's text, and sends a broken page to Tesseract tam: no Tamil text, private codes, NUL characters, or 3 or more signs that follow no letter.
python3 tamil_pdf_to_word.py in.pdf out.docx
- It needs pandoc, Poppler and Tesseract with tam.
- It deletes the U+200C that Tesseract writes after the pulli.
- It sent all 12 reportlab pages to OCR, and none of the 24 good ones.
- Why 3 signs: one proofread page has a stray ே after a pulli. With 1, that good page would go to OCR.
- The .docx is plain paragraphs, with no pictures, tables or layout.
tamil_pdf_to_word.py, the whole script
"""Tamil PDF to Word: an editable .docx. The script of brasspage.com/tamil-pdf-to-word/
Needs on your PATH: Poppler (pdftotext, pdftoppm), Tesseract with the tam model, and pandoc. Python 3, stdlib only.
python3 tamil_pdf_to_word.py in.pdf out.docx [tesseract language, default tam]
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 Tamil letters (a scan, or an old font such as Bamini that stores Latin codes), Private Use
Area characters, NUL characters, or 3 or more vowel signs or pulli that do not follow a consonant (the signs that
draw before a letter, such as the e sign, were stored in the wrong order). Tesseract writes a zero width non-joiner
(U+200C) after the pulli; the script deletes it, so a search in Word finds the word. Blank lines split paragraphs.
pandoc writes the .docx in Tamil (ta-IN), and set_tamil() marks it Tamil for complex script too (ta-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
TAMIL = re.compile("[\u0b82-\u0bcd\u0bd7]") # Tamil letters and signs
ORPHAN = re.compile("(?<![\u0b95-\u0bb9])[\u0bbe-\u0bcd\u0bd7]") # a sign that does not follow a consonant
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(TAMIL.findall(t)) < 20: # ponytail: an English-only page goes to OCR too
return "no Tamil 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 pulli not after a letter"
return None
def ocr(pdf, n, lang):
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", lang, "--dpi", "300"]
return subprocess.run(cmd, input=png, capture_output=True, check=True).stdout.decode().replace("\u200c", "")
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, lang="tam"):
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, lang) 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=ta-IN"], input=body.encode(), check=True)
set_tamil(docx)
def set_tamil(docx):
"""pandoc's styles keep Arabic as the complex-script language (w:bidi="ar-SA"). Make it Tamil."""
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="ta-IN"')
z.writestr(info, data)
if __name__ == "__main__":
pdf_to_docx(*sys.argv[1:4])
Bamini to Unicode, offline
Bamini fonts draw Tamil on Latin codes. I had no Bamini file, so two free tools wrote codes for our 693 words: Open-Tamil 1.1 and aril 0.1.1.
| Codes by | Open-Tamil reads | aril reads |
|---|---|---|
| Open-Tamil | 638 | 638 |
| aril | 675 | 691 |
aril -f bamini < codes.txt > tamil.txt
- Open-Tamil writes இ with the comma's code, so each இ word came back with a comma.
-
They write ூ differently on some letters
(கூ:
$orFh). Open-Tamil leaves aril's h as a Latin letter: 16 words. - Bamini's pulli is the semicolon key, so a semicolon right after a word like அல்ல came back as a pulli (2 words).
A look-alike Bamini PDF: aril reads it
My look-alike Bamini PDF drew aril's codes in DejaVu Sans: I found no Bamini font with a license.
aril read it back: 690 of 693 words. pdftotext, then Open-Tamil: 674.
aril -f bamini in.pdf -o out.txt
pandoc -f markdown out.txt -o out.docx -M lang=ta
The script sends such a page to OCR. On a real Bamini PDF, OCR sees the Tamil it draws. I could not test that: my look-alike draws Latin letters.
Our Actor: no install, no Tamil yet
Our Apify Actor, PDF to Markdown OCR, turns PDFs into Markdown in one call. It reads 23 languages, not Tamil 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 Tamil OCR.
How I tested
- Text: 12 passages from proofread ta.wikisource pages (public domain or CC0), one a page. I quote none of them.
- They hold 693 words, 896 pulli and 123 ை signs.
- One word ends in a stray ே after a pulli. OCR did not write it, so OCR can reach 692 of 693 words, and a text layer 693.
- PDFs in Noto Sans Tamil 2.004: Chromium 153 print to PDF and LibreOffice 26.8.1.1 export, both with lang ta, 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 tam and tessdata_best script/Tamil 4.1.0, pandoc 3.13.
- Words right: truth words found whole in the .docx text, each word counted as often as it appears. A U+200C makes a word count as wrong. Text from pdftotext and Tesseract went to pandoc for the .docx.
- I scored the text inside each .docx. LibreOffice on this Mac drew no Tamil when it printed the 4 from the Chromium PDF, so I did not check how they look.
- Bamini: Open-Tamil 1.1 (PyPI; only its txt2unicode folder) and aril-cli 0.1.1 (crates.io, built from source with its lock file). Both ran offline.
- The look-alike PDF: aril's codes drawn by reportlab in DejaVu Sans, so it copies like a Bamini PDF but does not look like one.
- Our Actor has no Tamil model, so it was not in this test.
Sources
- pdf2docx is MIT. It needs PyMuPDF, which is AGPL-3.0 or a paid license.
- Open-Tamil on PyPI: MIT in its metadata, but its txt2unicode converter files carry a GPL-3.0-or-later header.
- aril-cli on crates.io: MIT or Apache-2.0.
- tessdata_best and tessdata_fast for Tesseract (Apache-2.0).
- Font: Noto Sans Tamil, OFL.
- Scripts and results stay in our private repo, in research/bench/tamil-pdf-to-word-2026-11-28/.
- We make the Apify Actor, not these tools.
Questions people ask
How do I convert a Tamil PDF to Word for free?
Copy the PDF's own text where it is good, OCR the pages where it is broken with Tesseract tam, delete the U+200C it adds, then let pandoc write the .docx. The free script on this page did that on 3 typed PDFs: 99.3% to 100.0% of words right.
How do I convert Bamini to Unicode?
aril 0.1.1 read back the Bamini codes it wrote, offline: 691 of 693 words from text, 690 from a look-alike PDF. Open-Tamil 1.1 read those codes at 675. On Open-Tamil's codes, both read 638. I had no real Bamini file, only codes the two tools wrote.
Why does Tamil text from a PDF come out scrambled?
Some converters put Tamil signs and letters out of order: LibreOffice Writer got 0.1% to 2.3% of words right. Some PDFs keep private glyph codes in place of some letters, and then no copy works: OCR the page. pdftotext kept 100% on 2 of our 3 PDFs.