Flattening a PDF and getting it to print on letter-sized paper

I would never have believed how complicated this would wind up being.

Requirements:


 * PHP
 * ghostscript
 * imagemagick
 * Multivalent