pdf/margins

Build
Status

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.

It shells out to mudraw, part of mupdf, for rastering the PDF to PNGs, and then uses Chunky PNG to examine each page's margins.

On Ubuntu, you may wish to install mupdf from the PPA.

Written by Tom Taylor, Newspaper Club.

Example

# accepts a `spreads` boolean which assumes margin dimensions refer to
# spreads, and so alternates which pages we check left and right margins on
spreads = true
# measurements in mm, ordered top, right, bottom, left (same as CSS)
checker = PDF::Margins::Checker.new('example.pdf', 10, 10, 10, 10, spreads)
puts checker.issues.inspect