#!/usr/bin/perl # use for example as twopage.pl out.ps $flag = 0; # We have not yet found a page $even = 0; # First page is an odd page $page = 1; # Start at page #1 $pages = 1; # Allow %%Pages comment while (<>) { if (/^%%Pages:/ && $pages) { print "%%Pages: (atend)\n"; $pages = 0; } elsif (/^%%Page:/) { # We have found a page if ($flag) { print "restore\n"; # restore if it isn't the first } $flag = 1; if ($even) { # Translate for even pages print "save\n"; # gsave print "504 426 translate\n"; $even = 0; $page++; } else { # Translate for odd pages printf("%%%%Page: %d %d\n", $page, $page); print "save /showpage {} def\n"; print "504 30 translate\n"; $even = 1; } # Code to rotate and shrink print "90 rotate .5 .5 scale\n"; } elsif (/^%%Trail/) { # Cleanup if a %%Trailer is found if ($flag) { print "restore\n"; } print $_; printf("%%%%Pages: %d\n", $page); $flag = 0; } elsif (/^%%EOF/) { # Cleanup if an %%EOF is found if ($flag) { print "restore\n"; } print $_; $flag = 0; } else { print; } }