Script for Shifting Postscript pages
found a use yesterday for my interest in Postscript programming. I was trying to print out a draft copy of Alan Kennington’s book Differential geometry reconstructed: a unified systematic framework, but all the pages were coming out shifted up just enough to chop the page numbers off and irritate me. Hey, if I’m going to be printing 422 pages with my home printer, the output better be easy on the eyes! So, I used the copy of the DSC specs I printed (not for much, really– all I did was look up where to place the relevant instructions, and I could have intuited where they ended up– but maybe the specs will be more useful for something down the line) and the PLRM to figure out how to fix it.
Here is the resultant rough code:
use Getopt::Long;
GetOptions("scale=f@" => \@sf,
"offset=f@" => \@of );
#Make sure the scale factors aren't zero (Getopt makes non-specified
#argument values 0
$sx = $sf[0];
$sy = $sf[1];
$ox = $of[0] + 0;
$oy = $of[1] + 0;
for $val ($sx, $sy) {
$val = $val || 1;
}
while(<>) {
print;
if( /^%%BeginSetup/ ) {
print <<END;
<< /BeginPage { pop $ox $oy translate $sx $sy scale } >> setpagedevice
END
}
}
The option handling is perverse: to specify the offsets/scales, you must specify two single values instead of one list of two values, the way most programs accept arguments; i.e.:
| Acceptable | Unacceptable |
|---|---|
| -o 3 -o 72 | -o -3 -72 |
| --scale 3 --scale .25 | --scale 3 -.25 |
Now I’m tempted to attack the problem of blotting out certain page elements– Kennington has an illegible copyright notice affixed to the right hand side of every page, and a useless footer on easy page. Good book though, albeit unfinished.
Possibly relevant posts:
- Open Geometric problem (5/17/2006)
- Proposed Project (3/21/2002)
- LaTeX blogs– sounds sexy! (8/3/2001)