hpdft: PDF parsing library and CLI for text, layout, diff, images, and forms

[ library, mit, pdf, program ] [ Propose Tags ] [ Report a vulnerability ]

hpdft is a Haskell library and command-line tool for parsing PDF files. The library exposes document loading, geometry- and tagged-PDF text extraction, page-level paragraph regions, paragraph-level diff, image XObject export, and Form XObject extraction to standalone PDFs. The hpdft executable provides the same features for shell workflows. See docs/library.md for a usage guide and examples/ for sample programs.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.1.1, 0.1.1.2, 0.1.1.3, 0.4.6.0, 0.4.6.1, 0.4.6.2, 0.4.6.3, 0.4.6.4, 0.4.7.0 (info)
Change log CHANGELOG.md
Dependencies array (>=0.5 && <0.6), attoparsec (>=0.14.4 && <0.15), base (>=4.18.0 && <4.23), binary (>=0.8.9 && <0.9), bytestring (>=0.11.4 && <0.13), containers (>=0.6.7 && <0.9), crypton (>=0.34 && <0.36), deepseq (>=1.4.8 && <1.6), directory (>=1.3.8 && <1.4), dlist (>=1.0 && <1.1), file-embed (>=0.0.16 && <0.1), filepath (>=1.4.2 && <1.6), hpdft, memory (>=0.18.0 && <0.19), optparse-applicative (>=0.18.1 && <0.19), parallel (>=3.2.2 && <3.4), parsec (>=3.1.18 && <3.2), regex-base (>=0.94.0 && <0.95), regex-tdfa (>=1.3.2 && <1.4), semigroups (>=0.20 && <0.21), terminal-size (>=0.3 && <0.4), text (>=2.0.2 && <2.2.2), utf8-string (>=1.0.2 && <1.1), zlib (>=0.7.1 && <0.8) [details]
License MIT
Author Keiichiro Shikano
Maintainer k16.shikano@gmail.com
Uploaded by keiichiroShikano at 2026-07-05T23:42:05Z
Category PDF
Home page https://github.com/k16shikano/hpdft
Source repo head: git clone https://github.com/k16shikano/hpdft
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables page-api, extract-text, interpret-page, hpdft
Downloads 3928 total (15 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-07-05 [all 1 reports]

Readme for hpdft-0.4.6.3

[back to package description]

hpdft (Haskell PDF Tools)

CI

hpdft is a PDF parsing tool and library. It extracts text, metadata, and outlines (table of contents) from PDF files.

Quick start

cabal install
hpdft document.pdf                 # quick viewer (TUI in lower half of terminal)
hpdft text document.pdf            # high-quality text to stdout (tagged → geometry)
hpdft text -p 3 document.pdf       # page 3 only
hpdft text --geom document.pdf     # geometry-only extraction
hpdft text --legacy document.pdf   # fast stream-order text, streamed page by page

hpdft FILE (no subcommand) is a lightweight viewer: it shows fast stream-order text in an ANSI preview on a TTY, or streams it to stdout when piped. hpdft text FILE always writes high-quality tagged → geometry output to stdout. Legacy flat flags (hpdft -I FILE, hpdft -r REF FILE, etc.) still work but print a deprecation warning for non-text modes.

Command usage

hpdft FILE                                # quick viewer (TUI on a TTY, stream on a pipe)
hpdft text [OPTIONS] FILE                 # text extraction to stdout (tagged → geom)
hpdft image -p PAGE -o DIR FILE           # image XObjects from one page
hpdft form -p PAGE FILE                   # list top-level Form names (stdout)
hpdft form -p PAGE -n NAME -o DIR FILE    # extract one Form to standalone PDF
hpdft diff [OPTIONS] FILE_A FILE_B        # paragraph-level diff
hpdft info FILE                           # PDF metadata
hpdft title FILE                          # document title
hpdft toc FILE                            # table of contents
hpdft trailer FILE                        # PDF trailer dictionary
hpdft object -r REF FILE                  # show object by reference
hpdft refs FILE                           # page object references
hpdft grep -g REGEXP FILE                 # search extracted text

Text options:
  -p,--page PAGE           Page number (1-based; 0 = all pages)
  --geom                   Geometry-based layout extraction
  --tagged                 Tagged PDF structure extraction (default)
  --legacy                 Pre-0.3 stream-order extractor, streamed page by page
  --quiet                  Suppress page progress on stderr during --legacy streaming
  --footnotes              Inline footnote bodies as <footnote> tags
  --ruby                   Embed ruby in Aozora bunko notation
  -P,--password PASSWORD   Password for encrypted PDF
  FILE                     input pdf file
  -h,--help                Show help text

Image options:
  -p,--page PAGE           Page number (1-based, required)
  -o,--output DIR          Output directory (default: current directory)
  -P,--password PASSWORD   Password for encrypted PDF
  FILE                     input pdf file

Form options:
  -p,--page PAGE           Page number (1-based, required)
  -n,--name NAME           Top-level Form name (e.g. Fm42); omit to list names on stdout
  -o,--output DIR          Output directory (default: current directory)
  -P,--password PASSWORD   Password for encrypted PDF
  FILE                     input pdf file

Diff options:
  --json                   JSON output
  --ruby                   Embed ruby in Aozora bunko notation
  -P,--password PASSWORD   Password for encrypted PDF (both files)
  FILE_A FILE_B            PDF files to compare

hpdft FILE (no subcommand) opens the viewer: an ANSI preview in the lower half of the terminal showing fast stream-order text (j/k or arrow keys to scroll, d/u half page, g/G top/end, /PATTERN + n/N for regex search like less, q quit). When stdout is a pipe or file the viewer is skipped and the same text is streamed page by page.

hpdft text FILE extracts text in logical order using the tagged PDF structure when the document has a usable one, and otherwise falls back to geometry-based paragraph reconstruction (equivalent to --geom). -p N extracts one page with geometry layout. --legacy selects the fast stream-order extractor on stdout.

Library

hpdft is also a Haskell library. See docs/library.md for installation, error handling, text pipelines, page API, diff, images, and form extraction.

Module Purpose
PDF.Document Single-read document handle (openDocument)
PDF.Error PdfResult, PdfError, PdfWarning
PDF.Text Text extraction (tagged, geometry, legacy)
PDF.Layout LayoutOptions, line/paragraph layout
PDF.Page Page enumeration and structured extraction
PDF.Diff Paragraph-level document comparison
PDF.Image Image XObject extraction
PDF.FormExtract Form XObject extraction to standalone PDF
PDF.Interpret Content-stream geometry interpreter
PDF.Structure Tagged PDF logical structure

Example programs (from repo root):

cabal run extract-text -- data/fixtures/classic.pdf
cabal run page-api -- data/fixtures/paragraphs.pdf

Build Haddock API docs locally:

cabal haddock --haddock-all

Install

Clone this repository and run cabal-install.

cabal install

Development

Requires GHC 9.14+ (see hpdft.cabal).

cabal build
cabal test                              # golden (22) + unit
bash scripts/verify_text.sh             # compare all fixture outputs
cabal run interpret-page -- FILE PAGE   # debug glyph positions

Documentation

Developer notes (roadmaps, performance write-ups): dev/

Version

Released: 0.4.6.0 (2026-07-05) — Quick viewer (hpdft FILE) with ANSI TUI, legacy streaming, toc fix. Previous release: 0.4.5.0.