The output
Three formats from the same reading of the page: Markdown, plain text and JSON.
Markdown
The default. khpdf rebuilds the page structure:
- Headings from text noticeably larger or bolder than the body text.
- Paragraphs from lines that belong together.
- Lists that start with a bullet or a number such as ១.,
1)or ក. - Tables from text in aligned columns.
- A note in place of any page that is a scan:
> *[Page 3 appears to be image-only / scanned; OCR required]*
With --page-markers each page starts with <!-- Page N -->.
Plain text
The same content without Markdown symbols: one blank line between blocks, table cells separated by tabs. Good for search indexes, word counts and NLP tools. Page markers look like [Page N].
JSON
Everything khpdf knows about each page. This is real output for the first page of a World Bank report, shortened:
{
"page_count": 54,
"pages": [
{
"number": 1,
"width": 612.0,
"height": 792.0,
"needs_ocr": false,
"blocks": [
{ "type": "heading", "level": 1, "text": "SFG2319" },
{ "type": "paragraph", "text": "Public Disclosure Authorized ការរៀបចំក្របខ័ណ្ឌគ្រប់គ្រងបរិស្ថាន និងសង្គម" }
],
"fonts": [
{
"resource_name": "C2_0",
"base_font": "IWQNDZ+Khmer OS Muol Light",
"subtype": "Type0",
"encoding": "Identity-H",
"has_to_unicode": true,
"has_embedded_font": true,
"detected_legacy_family": null
}
],
"warnings": []
}
]
}| Block type | Fields |
|---|---|
heading | level (1–3), text |
paragraph | text |
list_item | marker, text |
table | headers (list of cells), rows (list of lists) |
page_count is the number of pages in the file; pages holds only the pages you asked for. width and height are in points (1/72 inch), measured in reading orientation. warnings lists anything worth knowing about the page, such as fonts with no mapping, sideways pages that were turned, or text drawn twice that was dropped.
Word positions
With --words (or words=True in Python), each page also has a words list: every word in drawing order with its box, in points.
"words": [
{"text": "ការបណ្តុះបណ្តាលក្នុងពេលបម្រើការងារ(IST)", "x0": 56.69, "y0": 57.21, "x1": 255.18, "y1": 77.09},
{"text": "សម្រាប់", "x0": 258.23, "y0": 57.21, "x1": 291.96, "y1": 77.09}
]Boxes are on the page as viewers show it: the crop box turned by the page's rotation, origin at the top-left corner, y growing downwards, the same space as pdftotext -bbox. x0, y0 is a box's top-left corner and x1, y1 its bottom-right; a box reaches from the font's ascent to its descent, so it covers Khmer marks above and below the line. A word is text between spaces. Khmer is often written without spaces between words, so a Khmer "word" may be a whole phrase. On a page khpdf turned to read sideways text, width and height are in reading orientation while word boxes stay on the displayed page.