Reading a form nobody made fillable
A fillable PDF tells you where to write. A print-out does not, and most of the forms people are actually handed are print-outs — a scan of a scan, or a pre-digital sheet that was typeset in 1940.
So the page itself has to be read. Rendered off-screen, binarised, and searched for two shapes.
Two shapes cover almost everything
A rule is a solid line with room to write above it. The tests that matter are the rejections: ink sitting on the line is underlined text, another rule within 18 points is a table, and a line half the page wide on a grid is a border. Without those, a dense tax form grows hundreds of blanks that nobody would ever write on.
A leader is the row of dots printed forms have used to mark a blank since before they were set by machine. The thing separating a leader from the last line of a paragraph is that a machine printed it: the dots are evenly spaced and all the same size. Drop that test and one form sprouts four hundred blanks.
Boxes come from where rules stop
The obvious way to find a boxed grid is to hunt for vertical strokes. On a real scan this finds almost nothing — the column lines are faint and broken.
But where a horizontal rule stops survives scanning perfectly, and those endpoints are exactly the column edges. A pair of edges crossed by two rules, with a free row inside, is a cell. Ink running down an edge only confirms a candidate, which a broken line still passes.
The part that is easy to get wrong
A scan’s paper is grey, not white. Compare every pixel against a fixed cutoff and the whole sheet reads as ink. Compare it against the average of a window around it and the page comes back clean.
And a box on a filled-in form is still a box. What matters is whether some row inside is free — including a solidly shaded one, because tax forms shade the areas you write in.