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.

pdftotextការររៀបចំត្រកបខ័ណឌត្ររប់ត្ររង
khpdfការរៀបចំក្របខ័ណ្ឌគ្រប់គ្រង

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.

pdftotextការបង្កើតមជ្ឈដ្ឋានអំងោយផលសម្រាប់ងសដ្ាកិច្ចឌីជ្ីថល
khpdfការបង្កើតមជ្ឈដ្ឋានអំណោយផលសម្រាប់សេដ្ឋកិច្ចឌីជីថល
pdftotextប្រពេសពនេះ អាតទញប្រពោជន៍េីសហគម្ន៍ពសដ្ាកិតចអាស៊ាន
khpdfប្រទេសនេះ អាចទាញប្រយោជន៍ពីសហគមន៍សេដ្ឋកិច្ចអាស៊ាន

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.

pdftotextការវាគតម្រៃបរ ិសាាន និងសងគរដំបូង
khpdfការវាយតម្លៃបរិស្ថាន និងសង្គមដំបូង

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.

pdftotextកាារអភិិវឌ្ឍឍមនុុស្សស គឺឺកាារផ្តោ�ោ�តលើ�ើមនុុស្សស
khpdfការអភិវឌ្ឍមនុស្ស គឺការផ្តោតលើមនុស្ស

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.

pdftotextesckþIEføgGMNrKuN
khpdfសេចក្តីថ្លែងអំណរគុណ

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.

pdftotextឆ្ន ំណំេោនទឹក ំនន់ខពស់
khpdfឆ្នាំដែលមានទឹកជំនន់ខ្ពស់

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.

naive reading| ្ស | ិង | ិវឌ | ាយ |
khpdfក្របខ័ណ្ឌយុទ្ធសាស្ត្រកម្មវិធីប្រចាំប្រទេស

Text drawn twice

Outline, shadow and fake-bold effects draw the same text twice, slightly offset. khpdf keeps one copy. ADB, 2012.

naive reading២០១២ ធនាគារអភិវឌ្ឍន៍អាស៊ី២០១២ ធនាគារអភិវឌ្ឍន៍អាស៊ី
khpdf២០១២ ធនាគារអភិវឌ្ឍន៍អាស៊ី

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.

naive reading| PJ | ០ ០ ១ ១ | | | |
khpdf| PJ | ០ | ០ | ១ | ១ |