#!/usr/bin/perl -w # This program seems to work most of the time, # but I'm not convinced the calculations are really right use strict; my $input = shift; # determine bounding box open BBOX, "gs -sDEVICE=bbox -dNOPAUSE -dBATCH -dSAFER -dFirstPage=2 -dLastPage=6 $input 2>&1 |" or die; my $left = 1000; my $bottom = 1000; my $right = 0; my $top = 0; while () { print STDERR $_; if (/BoundingBox: (\d+) (\d+) (\d+) (\d+)/) { $left = $1 if $left > $1; $bottom = $2 if $bottom > $2; $right = $3 if $right < $3; $top = $4 if $top < $4; } } print STDERR "$left $bottom $right $top\n"; my $hmargin = 72; $top += $hmargin; $bottom -= $hmargin; my $height = $top - $bottom; my $scale = 72 * 8.5 / $height; my $xoff = 72 * 8.5 + $bottom * $scale; my $yoff = $hmargin * 0.4 - $left * $scale; # random hack my $yoff2 = $yoff + 72 * 11 / 2; my $command = "pdf2ps $input - | pstops -pletter '2:0L\@$scale($xoff,$yoff)+1L\@$scale($xoff,$yoff2)'"; print STDERR "$command\n"; system($command);