added per-page trim; fixed off-by-one in layout