Parsers¶
- pdfexorcist.parse_rows(pages: Iterable[tuple[int, list[list[tuple[float, str]]]]], min_values: int = 1, fit_width: bool = False) Iterator[dict]¶
Default parser: one dict per value, keyed by KEY, plus the label text.
The row key leaves out a side label (a group name printed once left of the label column, beside its block of rows) wherever an engine puts it: on a line of its own, in a row’s first cell, or joined to a label that other rows show alone. Values on a line without a label take the label of the label-only line just above (a label wrapped onto two lines). A trailing number in a label (“below 20”) is read as a value; fit_width gives it back when the row is wider than the rows beside it.
- pdfexorcist.parse_by_columns(pages: Iterable[tuple[int, list[list[tuple[float, str]]]]], min_values: int = 2, tol: float = 0.45, placement: str = 'x') Iterator[dict]¶
Like parse_rows, but a value’s column comes from its x.
Column centres are the median x of the i-th value over rows with the page’s most common value count; each value goes to the nearest centre within tol x the spacing, so a value an engine missed shifts nothing. Tokens in one column are joined (“1” “437” -> “1437”).
placement=”both” also places values by their order and keeps a cell only where the two agree. Where they differ the engine reads both values there (a blank reads “”), so it loses its vote on that cell and the vote shows both readings. A row with fewer values than the page’s mode is skipped when one of its values has no column by x.
- pdfexorcist.group_words(words: list[tuple], gap: float = 8.0) list[list[tuple[float, str]]]¶
(x0, x1, y_bottom, text[, y_top]) words to lines of (x_centre, text) BoxCells.
A word joins a line when it overlaps the line’s first word by half the shorter height; a word without y_top is 1 pt tall. A word printed sideways joins the line through its middle. Copies of a word drawn again within COPY_PT (fake bold) count once. Label words within gap pt join one cell; values never join. A word printed flush (FLUSH_PT) joins without a space, as subscripts do (“PM2.5”).
- pdfexorcist.KEY: list[str] = ["page", "row", "col"]¶
The default parser’s key: a cell is named by its page, its row label and its column number.