Simple Ruby library to check a PDF for clear margin areas, by rendering to a bitmap, ensuring that the pixel area defined by each margin is empty.
This is a bit of a clumsy technique, but it's faster than parsing and understanding all the permutations of the PDF format that may result in an object being visible in the margins.
On Ubuntu, you may wish to install
mupdf from the PPA.
# Accepts a `spreads` option which assumes margin dimensions refer to # spreads, and so alternates which pages we check left and right margins # on. Measurements are in mm, defaulting to 0 unless specified. checker = PDF::Margins::Checker.new('example.pdf', top_margin: 10, right_margin: 10, bottom_margin: 10, left_margin: 10, spreads: true) puts checker.issues.inspect