#!/usr/bin/python # # Fix an EPS file so that high quality compression is used by the # PDF converter. # # This software is in the public domain. # See http://www.jwhitham.org.uk/ for updates. # # Version 1.0 - Initial release - 30/11/2006. # Version 1.1 - Bug fix for EPS files generated by GIMP - 02/03/2007. # import os, sys def EPS_Fixup(fn): f = file(fn, 'rt') remember = [] before = True for line in f: if (( before ) and ( len(line) > 3 ) and ( line[ 0 ] != '%' )): before = False remember.append("""systemdict /setdistillerparams known { << /ColorACSImageDict << /QFactor 0.15 /Blend 1 /ColorTransform 1 /HSamples [1 1 1 1] /VSamples [1 1 1 1] >> >> setdistillerparams } if\n""") remember.append(line) f.close() f = file(fn, 'wt') f.write(''.join(remember)) f.close() if ( __name__ == "__main__" ): if ( len(sys.argv) != 2 ): print "Usage: %s \n" print "A command is inserted into the EPS file to force the use" print "of high quality compression." sys.exit(1) EPS_Fixup(sys.argv[ 1 ])