def make_pdf_to_png_converter():
 tools_available = []
 try:
  check_output([str(u'pdftocairo'), u'-v'], stderr=subprocess.STDOUT)
  tools_available.append(u'pdftocairo')
 except:
  pass
 (gs, ver) = mpl.checkdep_ghostscript()
 if gs:
  tools_available.append(u'gs')
 if (u'pdftocairo' in tools_available):
  def cairo_convert(pdffile, pngfile, dpi):
   cmd = [str(u'pdftocairo'), u'-singlefile', u'-png', (u'-r %d' % dpi), pdffile, os.path.splitext(pngfile)[0]]
   check_output(cmd, shell=True, stderr=subprocess.STDOUT)
  return cairo_convert
 elif (u'gs' in tools_available):
  def gs_convert(pdffile, pngfile, dpi):
   cmd = [str(gs), u'-dQUIET', u'-dSAFER', u'-dBATCH', u'-dNOPAUSE', u'-dNOPROMPT', u'-sDEVICE=png16m', u'-dUseCIEColor', u'-dTextAlphaBits=4', u'-dGraphicsAlphaBits=4', u'-dDOINTERPOLATE', (u'-sOutputFile=%s' % pngfile), (u'-r%d' % dpi), pdffile]
   check_output(cmd, stderr=subprocess.STDOUT)
  return gs_convert
 else:
  raise RuntimeError(u'No suitable pdf to png renderer found.')

def make_pdf_to_png_converter ( ) : tools_available = [ ] try : check_output ( [ str ( u'pdftocairo' ) , u'-v' ] , stderr = subprocess . STDOUT ) tools_available . append ( u'pdftocairo' ) except : pass ( gs , ver ) = mpl . checkdep_ghostscript ( ) if gs : tools_available . append ( u'gs' ) if ( u'pdftocairo' in tools_available ) : def cairo_convert ( pdffile , pngfile , dpi ) : cmd = [ str ( u'pdftocairo' ) , u'-singlefile' , u'-png' , ( u'-r %d' % dpi ) , pdffile , os . path . splitext ( pngfile ) [ 0 ] ] check_output ( cmd , shell = True , stderr = subprocess . STDOUT ) return cairo_convert elif ( u'gs' in tools_available ) : def gs_convert ( pdffile , pngfile , dpi ) : cmd = [ str ( gs ) , u'-dQUIET' , u'-dSAFER' , u'-dBATCH' , u'-dNOPAUSE' , u'-dNOPROMPT' , u'-sDEVICE=png16m' , u'-dUseCIEColor' , u'-dTextAlphaBits=4' , u'-dGraphicsAlphaBits=4' , u'-dDOINTERPOLATE' , ( u'-sOutputFile=%s' % pngfile ) , ( u'-r%d' % dpi ) , pdffile ] check_output ( cmd , stderr = subprocess . STDOUT ) return gs_convert else : raise RuntimeError ( u'No suitable pdf to png renderer found.' )
returns a function that converts a pdf file to a png file .