Metadata-Version: 2.4
Name: khmerpdf
Version: 0.1.2
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Topic :: Text Processing :: Linguistic
Summary: Clean Khmer text out of PDFs that copy-paste mangles (Markdown, text or JSON)
Keywords: khmer,pdf,unicode,nlp,text-extraction,cambodia
License-Expression: Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://moriartyputh.github.io/khpdf/
Project-URL: Source, https://github.com/MoriartyPuth/khpdf

# khmerpdf (អក្សរ)

**Clean Khmer text out of PDFs that copy-paste mangles.** khpdf reads the fonts inside a PDF
and gives back correct Khmer Unicode as plain text, Markdown or JSON. The engine is written
in Rust; this package gives you it as a Python library and a `khpdf` command.

```bash
pip install khmerpdf
```

| Same page, two tools | Standard extraction (`pdftotext`) | khpdf |
| --- | --- | --- |
| World Bank 2016 (Word) | ការររៀបចំត្រកបខ័ណឌត្ររប់ត្ររង | ការរៀបចំក្របខ័ណ្ឌគ្រប់គ្រង |
| UNDP 2024 (InDesign) | កាារអភិិវឌ្ឍឍមនុុស្សស | ការអភិវឌ្ឍមនុស្ស |
| ILO manual (Limon font) | `esckþIEføgGMNrKuN` | សេចក្តីថ្លែងអំណរគុណ |

## Python

```python
import khpdf

text = khpdf.extract("report.pdf")                        # plain text
md = khpdf.extract("report.pdf", format="markdown")       # headings, lists, tables
text = khpdf.extract(pdf_bytes, pages=range(1, 4))        # bytes work too

doc = khpdf.extract_document("report.pdf")                # structured
for page in doc["pages"]:
    if page["needs_ocr"]:
        print("page", page["number"], "is a scan")
```

The package is installed as `khmerpdf` and imported as `khpdf`.

## Command line

```bash
khpdf report.pdf                 # Markdown in the terminal
khpdf report.pdf -o report.txt   # the format follows the file name (.md, .txt, .json)
khpdf docs/ -o out/ -r           # a whole folder
khpdf --help
```

## What it works on

PDFs with a text layer (made on a computer, not scanned): Word with Khmer OS fonts, Limon
legacy fonts, InDesign with complete fonts, tables and sideways pages. Scanned PDFs are
detected and reported as needing OCR; khpdf does no OCR.

Try it in your browser, read how it works, or report a PDF that comes out wrong:
[moriartyputh.github.io/khpdf](https://moriartyputh.github.io/khpdf/) ·
[github.com/MoriartyPuth/khpdf](https://github.com/MoriartyPuth/khpdf)

Apache-2.0.

