Return a function that converts a pdf file to a png file.
()
| 167 | |
| 168 | |
| 169 | def make_pdf_to_png_converter(): |
| 170 | """Return a function that converts a pdf file to a png file.""" |
| 171 | try: |
| 172 | mpl._get_executable_info("pdftocairo") |
| 173 | except mpl.ExecutableNotFoundError: |
| 174 | pass |
| 175 | else: |
| 176 | return lambda pdffile, pngfile, dpi: subprocess.check_output( |
| 177 | ["pdftocairo", "-singlefile", "-transp", "-png", "-r", "%d" % dpi, |
| 178 | pdffile, os.path.splitext(pngfile)[0]], |
| 179 | stderr=subprocess.STDOUT) |
| 180 | try: |
| 181 | gs_info = mpl._get_executable_info("gs") |
| 182 | except mpl.ExecutableNotFoundError: |
| 183 | pass |
| 184 | else: |
| 185 | return lambda pdffile, pngfile, dpi: subprocess.check_output( |
| 186 | [gs_info.executable, |
| 187 | '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT', |
| 188 | '-dUseCIEColor', '-dTextAlphaBits=4', |
| 189 | '-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', |
| 190 | '-sDEVICE=pngalpha', '-sOutputFile=%s' % pngfile, |
| 191 | '-r%d' % dpi, pdffile], |
| 192 | stderr=subprocess.STDOUT) |
| 193 | raise RuntimeError("No suitable pdf to png renderer found.") |
| 194 | |
| 195 | |
| 196 | class LatexError(Exception): |
no outgoing calls
no test coverage detected
searching dependent graphs…