def gs_distill(tmpfile, eps=False, ptype=u'letter', bbox=None, rotated=False):
 if eps:
  paper_option = u'-dEPSCrop'
 else:
  paper_option = (u'-sPAPERSIZE=%s' % ptype)
 psfile = (tmpfile + u'.ps')
 outfile = (tmpfile + u'.output')
 dpi = rcParams[u'ps.distiller.res']
 gs_exe = ps_backend_helper.gs_exe
 if ps_backend_helper.supports_ps2write:
  device_name = u'ps2write'
 else:
  device_name = u'pswrite'
 command = (u'%s -dBATCH -dNOPAUSE -r%d -sDEVICE=%s %s -sOutputFile="%s"                 "%s" > "%s"' % (gs_exe, dpi, device_name, paper_option, psfile, tmpfile, outfile))
 verbose.report(command, u'debug')
 exit_status = os.system(command)
 with io.open(outfile, u'rb') as fh:
  if exit_status:
   output = fh.read()
   m = u'\n'.join([u'ghostscript was not able to process your image.', u'Here is the full report generated by ghostscript:', u'', u'%s'])
   raise RuntimeError((m % output))
  else:
   verbose.report(fh.read(), u'debug')
 os.remove(outfile)
 os.remove(tmpfile)
 shutil.move(psfile, tmpfile)
 if eps:
  if ps_backend_helper.supports_ps2write:
   pstoeps(tmpfile, bbox, rotated=rotated)
  else:
   pstoeps(tmpfile)

def gs_distill ( tmpfile , eps = False , ptype = u'letter' , bbox = None , rotated = False ) : if eps : paper_option = u'-dEPSCrop' else : paper_option = ( u'-sPAPERSIZE=%s' % ptype ) psfile = ( tmpfile + u'.ps' ) outfile = ( tmpfile + u'.output' ) dpi = rcParams [ u'ps.distiller.res' ] gs_exe = ps_backend_helper . gs_exe if ps_backend_helper . supports_ps2write : device_name = u'ps2write' else : device_name = u'pswrite' command = ( u'%s -dBATCH -dNOPAUSE -r%d -sDEVICE=%s %s -sOutputFile="%s"                 "%s" > "%s"' % ( gs_exe , dpi , device_name , paper_option , psfile , tmpfile , outfile ) ) verbose . report ( command , u'debug' ) exit_status = os . system ( command ) with io . open ( outfile , u'rb' ) as fh : if exit_status : output = fh . read ( ) m = u'\n' . join ( [ u'ghostscript was not able to process your image.' , u'Here is the full report generated by ghostscript:' , u'' , u'%s' ] ) raise RuntimeError ( ( m % output ) ) else : verbose . report ( fh . read ( ) , u'debug' ) os . remove ( outfile ) os . remove ( tmpfile ) shutil . move ( psfile , tmpfile ) if eps : if ps_backend_helper . supports_ps2write : pstoeps ( tmpfile , bbox , rotated = rotated ) else : pstoeps ( tmpfile )
use ghostscripts pswrite or epswrite device to distill a file .