DEV Community

KovaPDF
KovaPDF

Posted on

Why text copied from some Bangla and Hindi PDFs comes out scrambled, and a 10 second test

You open a PDF in Bangla or Hindi. It looks perfect on screen. You copy one line, paste it into a chat or a search box, and get something like this:

On the page:   নমুনা প্রতিষ্ঠান লিমিটেড
After copying: নীমু নী প্র থিষ্ঠা নী থিথিমু টেড
Enter fullscreen mode Exit fullscreen mode

Same file, same line. The page is fine, the text behind the page is not. This post explains why that happens, how to test any PDF in about ten seconds, and what to do about it as the person who makes the PDF and as the person who receives it.

A PDF stores two things: the picture and the meaning

When a PDF draws a word, it does not store letters the way a Word file does. It stores glyph numbers: "draw shape 412 of this font here, then shape 87 there". That is enough to paint the page.

To get text back out (copy, search, screen readers, translation, AI summaries, PDF to Word), a reader needs a second piece of information: which Unicode characters each shape stands for. That map usually lives in the font's ToUnicode table inside the PDF.

For English this is easy. One letter, one shape, left to right.

For Bengali, Devanagari and other Indic scripts it is not:

  • Vowel signs are drawn in a different place from where they are typed. In কি the vowel sign ি is typed after ক but drawn to its left.
  • Conjuncts become one shape. ক্ষ or ন্ত is typed as three characters but drawn as a single glyph.
  • Some shapes have no single character at all. A half form or a reph is a piece of a cluster, not a letter on its own.

The font engine that made the PDF knew all of this when it drew the page. If it did not write a correct map back into the file, the meaning is lost, even though the picture is perfect.

What goes wrong, in the order you will usually see it

  1. Visual order instead of typed order. The reader takes shapes left to right, so ি comes out before the consonant it belongs to: কিছু becomes িকছু.
  2. Conjuncts with no map. The single shape for a conjunct maps to nothing, so letters vanish, or to one wrong letter.
  3. A wrong map. The shapes map to other characters altogether. That is the example at the top: every reader gets the same wrong text, because the wrong text is what the file says.
  4. Old non-Unicode fonts. Some documents were typed with fonts that put Bangla or Hindi shapes on Latin keyboard codes. The text inside is Latin letters that only look right in that one font.

None of these show on screen. All of them break copy, Ctrl+F, screen readers and every tool that reads the text.

The 10 second test

You do not need special software for a first check.

  1. Open the PDF in any viewer.
  2. Select one full line that has a few joined letters in it and copy it.
  3. Paste it into a plain text box (Notepad, a chat, a search bar) and compare it with the page.

If the pasted text matches, the text layer is healthy. If vowel signs jump to the start of words, letters are missing, or you see odd Latin letters inside Bengali or Hindi words, the text layer is broken.

Two more signs you can see without copying anything:

  • Ctrl+F cannot find a word you can see on the page.
  • A screen reader reads nonsense or skips the line.

If you prefer the command line, Poppler's pdftotext shows the same thing for a whole page:

pdftotext -f 1 -l 1 -layout letter.pdf -
Enter fullscreen mode Exit fullscreen mode

Compare the output with the page. Try two different readers (for example pdftotext and the copy in your browser's PDF viewer). If both give the same wrong text, the fault is in the file, not in the reader.

If you make the PDF

  • Export with a Unicode font that has proper shaping data (for example Noto Sans Bengali, Noto Sans Devanagari, Nirmala UI, Mangal, Vrinda), not an old non-Unicode font.
  • Use the program's own Export or Save as PDF rather than printing to a PDF printer driver. A print driver only sees shapes; it often has no idea which characters they came from.
  • Ask for PDF/A-2u or PDF/A-3u if your program offers it. The "u" level requires every character in the file to map to Unicode. It does not guarantee a perfect result for every font, but it makes the program try, and it is a clear thing to ask a supplier or a print shop for.
  • Run the 10 second test before you send the file. It catches the problem while you can still fix the source.

If you receive the PDF

You cannot repair a wrong map from the outside with certainty, because the file itself carries the wrong meaning. What works:

  • Ask the sender for the original document (Word, Google Docs) or a fresh export.
  • Read the page from its picture instead of its text layer. Text recognition (OCR) looks at the shapes the way you do, so it does not care how broken the hidden text is. Clean digital pages are sharper than any scan, so good Bangla and Hindi OCR usually reads them well.

One quick way to do the second step: take a screenshot of the page and run it through an image to text tool. We built one into KovaPDF (Image to Text) and tried it on the letter from the top of this post: the Bangla came back almost word for word, with only a couple of small slips in joined letters, where copying the text layer gave the scrambled line above. Any OCR you trust will do the same job; check names and numbers either way.

Why this matters more than it seems

A broken text layer is invisible to the person who made the file and to anyone who only reads it on screen. It shows up later: an applicant whose name cannot be found by search, an office notice a screen reader cannot read, a contract that an AI summary or a translation tool turns into nonsense. Ten seconds of copy and paste before sending is a cheap way to avoid all of that.

If you have a PDF where even OCR struggles, or a tool that handles this well, I would like to hear about it in the comments.

Top comments (0)