#!/usr/bin/perl use strict; # calculates a tight bounding box (using the 'gs' command) and sets that bounding box into . # This is useful where file.eps was created from Visio by printing to the Adobe Generic Postscript Printer into # based on TightBoundingBox.pl by Zasha Weinberg - http://bliss.biology.yale.edu/~zasha/latexexample/index.html if (@ARGV != 2) { die "Syntax: $0 \n" } my ($infile,$outfile) = @ARGV; # first, find bbox dimensions my $bbox; if (`gs -dNOPAUSE -dBATCH -sDEVICE=bbox -sOutputFile=- $infile 2>&1` =~ /^%%BoundingBox: (.*)/m) { $bbox = $1; } else { die "Unable to get bounding box size!"; } print "Got bbox $bbox\n"; # now substitute this into file my $got_bbox=0; open IN, "< $infile" or die "$infile: $!\n"; open OUT, "> $outfile" or die "$outfile: $!\n"; while () { if (s/^\%\%(.*)BoundingBox: .*/%%$1BoundingBox: $bbox/) { $got_bbox=1; } print OUT; } close(IN); close(OUT); if (!$got_bbox) { warn "WARNING: Couldn't find bounding box in file -- no change made.\n"; }