Scaling ROOT PostScript Files

I encountered some trouble today printing PostScript files from ROOT at smaller sizes. This is most useful to me because my lab notebook, heretically, is smaller than ‘letter’ size, which I find more convenient for carrying than the huge squared notebooks which seem to be the norm around here. I was looking for a quick way of printing PostScript at 80% scale.

The command lpr -o scaling=80 actually produced one page with a HUGE blow-up of one corner of my plot, so that obviously wasn’t working.

Using the built-in scaling in evince didn’t work either. I don’t know if that works on other files or not, I’ve never had any luck with it though.

Using the command psnup -2 (from GhostScript) should put two pages into one page (“2-up”) however it wasn’t working with the PostScript that ROOT produced, basically just giving garbage output. Looking around on the web, I found this post on the Root Talk forum which describes an extra PS command that ROOT inserts to keep CUPS happy, but which seems to break some aspects of GhostScript.

Removing the offending CUPS-appeasement lines does allow GhostScript to work with the files. You can do that with sed.
cat | sed -e "s/%%BeginSetup//" \
| sed -e "s/%%EndSetup//" >

With that fix in place, I decided that I could do better than psnup in order to resize the plots (80% is a better fit to my notebook). In the end, I came up with the following script:


# take ROOT output (or any postscript) and strip the 
# extra commands that seem to break GhostScript, 
# then resize to 70% of the size and print


function usage() {
    echo "Usage: lpr_70 [lpr options]"
    exit 2

# separate postscript file from other lpr arguments
for arg in $*; do
    ext=`echo "$arg" |awk -F '.' '{print $NF}'`
    if [ "$ext" == "ps" ]; then
    elif [ "$arg" == "--help" ]; then
        lpr_args="$lpr_args $arg"

# parse the filename a little
ext=`echo "$input" |awk -F '.' '{print $NF}'`
base=`basename "$input" .$ext`

# strip the extra ROOT postscript commands that cause trouble
cat $input | sed -e "s/%%BeginSetup//" | sed -e "s/%%EndSetup//"  > $temp1

# Scale using pstops
pstops -p$paper 1:0@$scale $temp1 $temp2

# Send to the printer
lpr $lpr_args $temp2

# remove the temporary files
rm $temp1 $temp2