I'm looking for a command line tool that can be used to determine if a page in a PDF document has ink in the margins. Ideally, you'd be able to specify a region – say, within 1 inch of edge of the page – and it would report which pages have any ink in that region.
My motivation is to be able to quickly find which pages in a long typeset document (from LaTeX as it happens) have bits that have found their way into the margins so I can quickly determine which parts of the source document need to be modified manually to clean up the layout. (Just checking for LaTeX overfull boxes doesn't get at the problem because LaTeX doesn't always report these intrusions as overfull boxes, and many overfull boxes are benign.)
I've shown an example page here to give the idea. The yellow box was added to indicate the intended margin. Note (red arrow) that a floating figure has floated out of the text block into the margin region. That's the kind of thing I'd like to find programmatically.
Pointers to tools that don't do this directly but that could be cobbled together to do this would also be valuable. For instance, checking a single page would be sufficient, since it could be wrapped in a script to split the PDF into pages and check each individually. A tool that could perform a similar function for an arbitrary rectangle would be sufficient, since the "margin" could be defined as a set of rectangles. You get the idea (I hope).
Any help greatly appreciated.