Command line
One PDF, many PDFs or whole folders, to Markdown, plain text or JSON.
khpdf [OPTIONS] <PDF_OR_FOLDER>...
Examples
khpdf report.pdf # Markdown in the terminal khpdf report.pdf -o report.md # save it (the format follows the file name) khpdf report.pdf -o report.txt # plain text khpdf report.pdf -o report.json # structured JSON khpdf *.pdf -o out/ # many PDFs into a folder khpdf docs/ -o out/ -r # a whole folder, subfolders too khpdf report.pdf --pages 1-3,5 # only some pages khpdf report.pdf --inspect-fonts # which fonts are inside, and how each is decoded
Options
| Option | What it does |
|---|---|
-o, --output PATH | A file for one PDF, or a folder for several. A path ending in / is always a folder. |
-f, --format md|txt|json | Output format. Without it, the output file's extension decides, else Markdown. |
-p, --pages PAGES | Only these pages: numbers and ranges like 1,3-5. |
-r, --recursive | Also look for PDFs in subfolders. |
--page-markers | Mark where each page starts. |
--pretty | Indent JSON for reading. |
--words | In JSON, list every word with its box on the page. See The output. |
-q, --quiet | Print only errors. |
--inspect-fonts | Show each page's fonts and how khpdf decodes them, instead of the text. See Troubleshooting. |
--no-normalize | Keep glyphs in the order the PDF stores them. |
--no-legacy | Do not decode Limon legacy fonts. |
Where the results go
- One PDF, no
-o: printed to the terminal. - One PDF,
-o file: written to that file. - Several PDFs or a folder:
-omust be a folder; it is created if needed. Each PDF becomesname.md(or.txt,.json). With-r, subfolders are mirrored, so two files with the same name in different folders don't overwrite each other.
Messages and exit codes
Each saved PDF gets a one-line summary on stderr, and a batch ends with a total. Scanned PDFs are pointed out. Errors are explained in plain words (`nope.pdf` does not exist, not a readable PDF).
| Exit code | Meaning |
|---|---|
| 0 | Everything converted |
| 1 | At least one PDF failed |
| 2 | The command itself was wrong (unknown option, missing file name) |