Probability with money attached

Dean Lee

markets are probability with money attached.

<- all essays

AI Economics

The Cost of Getting a PDF's Reading Order Wrong

A cheap text extraction can move the bill to review when columns, tables, or scanned pages lose their structure.

A developer building a search index from PDF reports has a practical choice: extract plain text first, or spend more effort preserving the page’s structure. Plain text is a sensible starting point for simple files. Its price is harder to judge when a two-column page or a table reaches the index in an order that changes its meaning.

PyMuPDF’s text extraction documentation describes the problem plainly. A PDF’s stored text can come out in an unexpected reading order, even when the page looks right in a viewer. The documentation gives an example in which a header added after the original content appears at the end of the extracted page. Sorting text by position can help; it is still a rule applied to the page, not proof that the resulting sequence matches the author’s intent.

The difference matters for a retrieval system. If the extracted text joins the end of one column to the beginning of another, a search result can present neighboring sentences that were never neighbors on the page. A model receiving that passage has no direct way to recover the original visual arrangement from plain text alone. A citation to the page helps a reviewer find the source, but it does not repair the extracted passage.

Tables need their own check

A table visible in a PDF often consists of ordinary text arranged to look tabular, according to the PyMuPDF documentation. The extractor has to identify the table’s area and its row and column boundaries. The library provides Page.find_tables() for that task; the documentation also notes that the work depends on details such as lines and other graphics.

For an evaluation, pick a table where a number’s meaning depends on its row and column. Compare the extracted header, value, unit and footnote with the page. A parser can return every visible number and still attach one to the wrong category. Checking only whether the value appears somewhere in the output will miss that error.

Scans add a different problem. PyMuPDF’s FAQ explains that an image-only scan needs OCR, while missing character mappings can also produce empty or garbled text. OCR creates text to inspect; it does not establish that every digit or symbol was recognized correctly. For a financial table, the review should include signs, decimal points and units because each can change the answer.

Compare the full cost

A useful trial keeps a small, representative set of documents and records the time spent correcting extraction as well as the processing charge. Include a normal text page, a multi-column page, a table and a scan if those appear in the intended workload. Store the page number with each passage so that a reviewer can return to the source. The sample should reflect the documents the system will actually receive; a result on clean reports says little about scanned forms.

The cheaper route depends on volume and on the cost of an error. For a low-stakes search over clean documents, plain extraction plus occasional review may be enough. When a workflow relies on a table’s figures, the time to reconcile those figures belongs in the comparison. A more structured conversion is worth considering if it reduces correction work on the files in the test, but neither a Markdown file nor a successful API response guarantees an accurate table.

The decision is easier when the acceptance test names the mistakes the team cannot afford: a missing minus sign, a value under the wrong year, or a passage assembled from two columns. Keep the original page available alongside the extracted text, and measure both the conversion and the work required to make the result usable.