#!/usr/bin/python import sys import os import string if __name__=='__main__': file_root = sys.argv[1] ps_file = file_root+'.eps' bbox_file = file_root+'.bbox' tmp_file = file_root+'.tmp' print 'Postscript file =',ps_file os.system('gs -dBATCH -dNOPAUSE -q -sDEVICE=bbox ' +ps_file+' 2> '+bbox_file) bbox = open(bbox_file,'r') box = bbox.readline() bbox.close() os.system('rm '+bbox_file) ps = open(ps_file,'r') tmp = open(tmp_file,'w') flag = 1 bb = '%%BoundingBox' print box while 1: line = ps.readline() if not line: break if flag: if string.find(line,bb) > -1: flag = 0 tmp.write(box) else: tmp.write(line) else: tmp.write(line) ps.close() tmp.close() os.system('rm '+ps_file) os.system('mv '+tmp_file+' '+ps_file)