Metadata-Version: 2.4
Name: kurdpdf
Version: 0.1.0
Summary: Convert Central Kurdish (Sorani) PDFs to text, Markdown, DOCX and JSON, with HarfBuzz glyph recovery
Keywords: kurdish,sorani,ckb,pdf,harfbuzz,text-extraction
Author: Dolan H.
Author-email: Dolan H. <0xdolan@gmail.com>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Topic :: Utilities
Requires-Dist: pillow>=11,<14
Requires-Dist: pymupdf>=1.26,<2
Requires-Dist: python-docx>=1.1,<2
Requires-Dist: rich>=14,<15
Requires-Dist: uharfbuzz>=0.50,<1
Requires-Dist: zimankit>=0.5.1,<0.6
Requires-Dist: pyarrow>=20 ; extra == 'lexicon'
Requires-Python: >=3.14
Project-URL: Homepage, https://github.com/kanilabs/kurdpdf
Project-URL: Documentation, https://kanilabs.github.io/kurdpdf/
Project-URL: Issues, https://github.com/kanilabs/kurdpdf/issues
Project-URL: Changelog, https://kanilabs.github.io/kurdpdf/changelog/
Provides-Extra: lexicon
Description-Content-Type: text/markdown

<p align="center"><img src="https://raw.githubusercontent.com/kanilabs/kurdpdf/main/docs/assets/banner.png" alt="KurdPDF: correct Central Kurdish text from any PDF" width="800"></p>

<p align="center">
<a href="https://github.com/kanilabs/kurdpdf/blob/main/LICENSE"><img alt="License: GPL-3.0-or-later" src="https://img.shields.io/badge/license-GPL--3.0--or--later-1D4A2E"></a>
<a href="https://pypi.org/project/kurdpdf/"><img alt="PyPI" src="https://img.shields.io/pypi/v/kurdpdf?color=1D4A2E"></a>
<a href="https://github.com/kanilabs/kurdpdf/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/kanilabs/kurdpdf/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://kanilabs.github.io/kurdpdf/"><img alt="Docs" src="https://img.shields.io/badge/docs-kanilabs.github.io-1D4A2E"></a>
<img alt="Python 3.14+" src="https://img.shields.io/badge/python-3.14%2B-1D4A2E">
<img alt="Runs offline" src="https://img.shields.io/badge/runs-offline-FEBD11">
</p>

# KurdPDF

Get correct Central Kurdish (Sorani, `ckb`) text out of PDFs. · دەقی کوردی بە دروستی لە PDF دەربهێنە.

Copying text from many Kurdish PDFs gives Latin gibberish (`†òÔð ØíŠ†ñ` instead of `دەقی کوردی`), reversed or disconnected letters, or empty boxes. The cause is the fonts: legacy Latin-mapped fonts (Ali-K, Ali-A and others), presentation-form text, broken ToUnicode maps, opaque Type 3 fonts, and scanned pages. KurdPDF inspects every font in the PDF, identifies glyphs by their outlines with HarfBuzz, and picks the right way to recover each one. Everything runs on your computer.

<p align="center"><img src="https://raw.githubusercontent.com/kanilabs/kurdpdf/main/docs/assets/before-after.png" alt="Copied from the PDF: Latin gibberish. Read by KurdPDF: دەقی کوردی دروست" width="600"></p>

## Features

- **Every kind of broken Kurdish PDF**: legacy fonts (Ali-K, Ali-A, Zanest, and the Halabja family: Halabja, Mewlewi, Nali, Kerkuk, Diyarbekir, Nesrin), wrong or missing ToUnicode maps, private-use and glyph-order maps, presentation forms in visual order, separate dot and mark glyphs, Windows printer-driver fonts, and scanned pages (OCR with Tesseract). Fonts are identified by glyph outlines, never by name.
- **Checked, not guessed**: each page is shaped again with HarfBuzz and compared with the glyphs drawn; look-alike letters (ک/ك, ی/ي, ە/ه) are settled with a Sorani word list you import; glyphs nothing can read are reported, never invented.
- **Nine formats**: TXT, Markdown, DOCX (Word), ODT (LibreOffice), RTF, HTML, LaTeX (polyglossia, Sorani), EPUB and JSON (with a JSON Schema). Right-to-left paragraphs, Sahel for Kurdish and Manrope for Latin text by default (`--font` picks another).
- **Page structure**: paragraphs, headings, lists and ruled tables kept; page numbers and running heads left out on request; two-column and two-page spreads read in order.
- **Faithful layers**: the raw and resolved text stay as the PDF draws it; a separate orthography layer (zimankit's Sorani rules) normalizes only Kurdish lines, and every rule can be turned off.
- **Page tools**: `kurdpdf pages` shows, extracts, splits, merges, turns, deletes and renders pages, and can convert what it cuts.
- **A local web page** (`kurdpdf web`): a PDF page editor, a reader with page images beside the text and synced scrolling, fonts you choose (kept in your browser), and Save as… in every format. Installable as an app.
- **Batch conversion** of files, folders and globs with progress; a failing file never stops the others.
- **For AI coding agents**: `kurdpdf skill install` adds a skill that teaches Claude Code and similar agents to convert and diagnose Kurdish PDFs.

## Install

With [uv](https://docs.astral.sh/uv/) (Python 3.14+):

```sh
uv tool install kurdpdf          # the kurdpdf command, in its own environment
uvx kurdpdf book.pdf             # or run it once without installing
uv add kurdpdf                   # as a library in a uv project (after uv init)
```

`pipx install kurdpdf` works too. From source: `uv sync`, then `uv run kurdpdf --help`. See [docs/install.md](https://kanilabs.github.io/kurdpdf/install/) for plain virtual environments, the fonts for exported files, and OCR (Tesseract 5 with a Central Kurdish model).

## Use

```sh
kurdpdf atlas build --font ~/fonts/kurdish   # once: reference fonts for glyph recovery
kurdpdf lexicon import words.tsv         # optional: a Sorani word list for look-alike letters
kurdpdf inspect book.pdf                 # which fonts, which classes, which pages are scanned
kurdpdf book.pdf                         # writes book.txt next to the PDF
kurdpdf book.pdf --format docx,odt,md --out out/   # Word, LibreOffice and Markdown
kurdpdf convert books/ --recursive --format all --out out/   # every format
kurdpdf pages extract book.pdf --pages 5-20 --format docx    # cut pages and convert them
kurdpdf pages merge cover.pdf book.pdf:3-200 -o clean.pdf
kurdpdf web                              # the page editor and reader in your browser
kurdpdf help pages split                 # help with examples for any command
kurdpdf manual                           # full manual
```

```python
from kurdpdf import KurdPDF

doc = KurdPDF("book.pdf").extract()
for font in doc.fonts:
    print(font.name, font.font_class)
print(doc.pages[0].best_text())
```

## Font classes

| Class | Meaning |
|---|---|
| C1 | Unicode text, usable as is |
| C2 | Broken map (U+FFFD or private-use characters) |
| C3 | Presentation forms, often in visual order |
| C4 | Legacy Latin-mapped Kurdish font |
| C5 | Opaque font program (MSTT31, Type 3) |
| C6 | Font not embedded or not loadable |

Scanned pages are reported as page method `no-text` and read by OCR when Tesseract is installed. Details in [docs/fonts-and-atlas.md](https://kanilabs.github.io/kurdpdf/fonts-and-atlas/).

## Known limits

- Without an atlas built from fonts like the ones in your PDFs, broken text layers (C2) can only be partly recovered.
- Legacy families other than Ali-K, Ali-A, Zanest and the Halabja family (Halabja, Mewlewi, Nali, Kerkuk, Diyarbekir, Nesrin) are not read yet.
- OCR makes about 7 character errors in 100 on prose and does badly on classical poetry; see [docs/ocr.md](https://kanilabs.github.io/kurdpdf/ocr/).
- Tables without ruling lines are read as lines, row by row; tables printed sideways are not recognised.

## Roadmap

- Tables for more legacy families.
- A desktop app around the web page.

## Documentation

**https://kanilabs.github.io/kurdpdf/**

[Install](https://kanilabs.github.io/kurdpdf/install/) · [Usage](https://kanilabs.github.io/kurdpdf/usage/) · [Brand](https://github.com/kanilabs/kurdpdf/blob/main/docs/brand.md) · [Launch kit](https://github.com/kanilabs/kurdpdf/blob/main/docs/launch.md) · [Fonts and atlas](https://kanilabs.github.io/kurdpdf/fonts-and-atlas/) · [OCR](https://kanilabs.github.io/kurdpdf/ocr/) · [Architecture](https://kanilabs.github.io/kurdpdf/architecture/) · [Kurdish support checks](https://kanilabs.github.io/kurdpdf/kurdish-support/) · [Development](https://kanilabs.github.io/kurdpdf/development/) · [Changelog](https://kanilabs.github.io/kurdpdf/changelog/) · [Contributing](https://kanilabs.github.io/kurdpdf/contributing/). The full manual: `kurdpdf manual`.

## Development

```sh
uv run pytest
uv run ruff check .
uv run ruff format --check .
```

Test PDFs are generated at test time. Real sample PDFs and fonts are kept locally and never committed. See [AGENTS.md](https://github.com/kanilabs/kurdpdf/blob/main/AGENTS.md).

## Related

- [zimankit](https://github.com/0xdolan/zimankit): Kurdish normalization, orthography and word list, used by KurdPDF's text layer.

## License

GPL-3.0-or-later; see [LICENSE](https://github.com/kanilabs/kurdpdf/blob/main/LICENSE). PyMuPDF is AGPL-3.0: running KurdPDF as a network service also means meeting the AGPL terms for PyMuPDF.
