khpdf case studies

Case studies

khpdf turns Khmer PDFs into correct Unicode text. Each case study looks at one problem from building it: what went wrong, why, how it was found and how much the fix changed. A plain explanation comes first, with technical detail underneath.

Trust the font, not the label

In a 54-page World Bank report made in Word, 34,277 of the 83,821 Khmer glyphs drawn carry a label that disagrees with the embedded font, so copied text comes out scrambled. khpdf reads the letters from the font itself and recovers the heading ការរៀបចំក្របខ័ណ្ឌគ្រប់គ្រង where pdftotext gives ការររៀបចំត្រកបខ័ណឌត្ររប់ត្ររង.

Contents: a glyph-by-glyph explorer of a real heading, one glyph with four different labels, the pipeline that asks the font, identical Khmer OS shapes in reports seven years apart, and finding ្ and ា from the jobs they do.

Same PDF, different text every run

Twenty runs on the same UNDP report gave four different outputs. The cause was a race in the PDF library over a page saved in four copies. Turning the race off made every run identical but left 8 of 11 pages wrong; reading the file's own index made them right.

Contents: a replay of the 20 real runs, a map of the copies inside the file, the race in lopdf, and the two fixes.

Part of khpdf. Code: GitHub · Package: PyPI · More examples: Problems khpdf fixes