|
6 | 6 | import datetime
|
7 | 7 | from enum import Enum
|
8 | 8 | import functools
|
9 |
| -import glob |
10 | 9 | from io import StringIO
|
11 | 10 | import logging
|
12 | 11 | import math
|
@@ -1214,32 +1213,26 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
|
1214 | 1213 | mpl._get_executable_info("gs") # Effectively checks for ps2pdf.
|
1215 | 1214 | mpl._get_executable_info("pdftops")
|
1216 | 1215 |
|
1217 |
| - pdffile = tmpfile + '.pdf' |
1218 |
| - psfile = tmpfile + '.ps' |
1219 |
| - |
1220 |
| - # Pass options as `-foo#bar` instead of `-foo=bar` to keep Windows happy |
1221 |
| - # (https://www.ghostscript.com/doc/9.22/Use.htm#MS_Windows). |
1222 |
| - cbook._check_and_log_subprocess( |
1223 |
| - ["ps2pdf", |
1224 |
| - "-dAutoFilterColorImages#false", |
1225 |
| - "-dAutoFilterGrayImages#false", |
1226 |
| - "-sAutoRotatePages#None", |
1227 |
| - "-sGrayImageFilter#FlateEncode", |
1228 |
| - "-sColorImageFilter#FlateEncode", |
1229 |
| - "-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype, |
1230 |
| - tmpfile, pdffile], _log) |
1231 |
| - cbook._check_and_log_subprocess( |
1232 |
| - ["pdftops", "-paper", "match", "-level2", pdffile, psfile], _log) |
1233 |
| - |
1234 |
| - os.remove(tmpfile) |
1235 |
| - shutil.move(psfile, tmpfile) |
1236 |
| - |
| 1216 | + with TemporaryDirectory() as tmpdir: |
| 1217 | + tmppdf = pathlib.Path(tmpdir, "tmp.pdf") |
| 1218 | + tmpps = pathlib.Path(tmpdir, "tmp.ps") |
| 1219 | + # Pass options as `-foo#bar` instead of `-foo=bar` to keep Windows |
| 1220 | + # happy (https://www.ghostscript.com/doc/9.22/Use.htm#MS_Windows). |
| 1221 | + cbook._check_and_log_subprocess( |
| 1222 | + ["ps2pdf", |
| 1223 | + "-dAutoFilterColorImages#false", |
| 1224 | + "-dAutoFilterGrayImages#false", |
| 1225 | + "-sAutoRotatePages#None", |
| 1226 | + "-sGrayImageFilter#FlateEncode", |
| 1227 | + "-sColorImageFilter#FlateEncode", |
| 1228 | + "-dEPSCrop" if eps else "-sPAPERSIZE#%s" % ptype, |
| 1229 | + tmpfile, tmppdf], _log) |
| 1230 | + cbook._check_and_log_subprocess( |
| 1231 | + ["pdftops", "-paper", "match", "-level2", tmppdf, tmpps], _log) |
| 1232 | + shutil.move(tmpps, tmpfile) |
1237 | 1233 | if eps:
|
1238 | 1234 | pstoeps(tmpfile)
|
1239 | 1235 |
|
1240 |
| - for fname in glob.glob(tmpfile+'.*'): |
1241 |
| - os.remove(fname) |
1242 |
| - |
1243 | 1236 |
|
1244 | 1237 | def get_bbox_header(lbrt, rotated=False):
|
1245 | 1238 | """
|
|
0 commit comments