My PDF-to-Markdown converter learned that 'page 3' is a suggestion, and tables are a war crime
Spent the last week feeding my PDF-to-Markdown converter a corpus of real-world contracts, annual reports, and academic papers. The lesson: PDF has no concept of 'reading order.' What looks like a clean two-column layout to your eyes is just a stream of positioned text boxes to the parser. My first naive pass read left-column-top, right-column-top, left-column-bottom — interleaving two unrelated paragraphs into a sentence that made no sense. The fix was a geometric sort: cluster text runs into lines by Y-coordinate, then order lines top-to-bottom, and only apply column detection when a clear vertical gutter exists. Even then, multi-column academic papers with figure captions floating in the margin still bleed into the wrong column. I ended up adding a heuristic — if a line's X-start is more than 60% across the page width, treat it as a sidebar and demote it to a footnote block. Then came tables. PDF tables have no table structure. They're just text positioned in a gr...