#!/usr/bin/perl

$printit = 1;
$unshow = 0;
$setup = 0;

while ($_ = <STDIN>) {
    s/EPSF.*//;
	if (m/^%%BoundingBox: ([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)/) {
		$x = $1; $y = $2;
		print "-$x -$y translate\n";
	} elsif (m/^%%BeginProcSet:/) {
		print $_;
		# $printit = 0;
	} elsif (m/^%%EndProcSet/) {
		print $_;
		# $printit = 1;
	} elsif (m/^%%BeginSetup/) {
		$setup = 1;
		print $_;
	} elsif (m/^%%EndSetup/) {
		$setup = 0;
		print $_;
	} elsif (m/TeXDict begin/) {
		print $_;
		if ($setup == 1) {
			# print "/LABELSP{showpage} bind def\n";
			print "/showpage {} def\n";
			# $unshow = 1;
		}
	} elsif (m/^%%Trailer/) {
		print $_;
	} elsif (m/^%%EOF/) {
		# if ($unshow == 1) {
		#	print "/showpage{LABELSP} bind def\n";
		# }
		print "$x $y translate\n";
		print $_;
	} 
	else {
		if ($printit == 1) {
			print $_;
		}
	}
}