Problems khpdf fixes
Every Khmer PDF problem khpdf handles, each found in a real document and covered by a test.
"pdftotext" below is Poppler's standard text extractor, a fair stand-in for what most tools and copy-paste give you.
Two of these problems are told in depth, with interactive figures, in the case studies: Trust the font, not the label (wrong labels and stripped fonts) and Same PDF, different text every run (a file saved several times).
Wrong labels from Word
A PDF carries a map from glyphs to letters, /ToUnicode. For Khmer, Word fills it in badly: each glyph gets one label, and a glyph shared by many words is often labelled wrongly, in a different way in each file. Here the pre-base ្រ glyph, used in hundreds of words, is labelled ត្រ. khpdf ignores those labels when the embedded font itself says what the glyph is. World Bank, 2016.
Case study: Trust the font, not the label →
Stripped fonts
PDFs embed only the parts of a font they use, and the tables that name glyphs are often thrown away. khpdf works around it two ways: Khmer OS fonts all share one glyph layout, which khpdf carries with it; and the coeng sign ្ and the vowel ា are recognised from their role in the font's combining rules. ADB 2023 and 2014.
Visual order and detached marks
PDFs store glyphs in the order they are drawn. In Khmer, េ ែ ៃ and ្រ are drawn before the consonant they belong to, and some vowels are drawn as two pieces. Small marks such as ិ or ុ are separate fragments placed over or under the previous letter. khpdf keeps marks with their syllable and moves everything into Unicode order. World Bank, 2016.
InDesign placeholders
InDesign draws a letter pair such as ភា as one glyph and adds an invisible placeholder labelled with the absorbed vowel, so every ា comes out twice. khpdf drops placeholders that repeat a vowel the syllable already has. UNDP, 2024.
Limon legacy fonts
Before Unicode, Khmer was typed with Latin letters in fonts like Limon that draw them as Khmer. The text is literally esckþIEføgGMNrKuN. khpdf decodes it, including when PDF producers split one word across several font copies, mark it with the Mac character set, or label a glyph with a look-alike character. ILO manual; LICADHO, 2004.
Strings in the wrong format
Some files write text in the wrong byte width: plain ASCII inside a two-byte font (table-of-contents dots and page numbers) or two-byte glyph numbers inside a one-byte font (footnotes). Viewers show garbage; khpdf recognises both patterns and decodes them correctly. World Bank, 2016.
Sideways pages
Landscape diagrams are often stored as portrait pages with the text running vertically. Read naively, each line falls apart into one-letter fragments. khpdf checks which way most of the text runs and turns the page so it reads left to right. ADB 2011 and 2012.
Text drawn twice
Outline, shadow and fake-bold effects draw the same text twice, slightly offset. khpdf keeps one copy. ADB, 2012.
Tables
A table row is sometimes drawn as one string with stretched spaces between the columns, and headers are often centred while the data is left-aligned. khpdf splits rows at wide gaps and matches columns by how much they overlap. LICADHO, 2004.