|
18 | 18 | import sys |
19 | 19 | import copy |
20 | 20 | import subprocess |
| 21 | +from distutils import spawn |
21 | 22 | WriteTexNS = u'http://wanglongqi.github.io/WriteTeX' |
22 | 23 | # from textext |
23 | 24 | SVG_NS = u"http://www.w3.org/2000/svg" |
@@ -164,23 +165,24 @@ def effect(self): |
164 | 165 | tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file), shell=True) |
165 | 166 |
|
166 | 167 | try: |
167 | | - # Here is a bug in pdfcrop, no idea how to fix. |
168 | | - crop_cmd = 'pdfcrop "%s"' % pdf_file |
169 | | - crop = subprocess.Popen(crop_cmd, |
170 | | - stdout=subprocess.PIPE, |
171 | | - stderr=subprocess.PIPE, |
172 | | - shell=True) |
173 | | - out = crop.communicate() |
174 | | - if len(out[1]) > 0: |
175 | | - inkex.errormsg("Error in pdfcrop:\n") |
176 | | - inkex.errormsg(" CMD executed: %s\n" % crop_cmd) |
177 | | - for msg in out: |
178 | | - inkex.errormsg(msg) |
179 | | - inkex.errormsg("Process will continue without crop") |
180 | | - |
181 | | - if os.path.exists(crop_file): |
182 | | - os.remove(pdf_file) |
183 | | - os.rename(crop_file, pdf_file) |
| 168 | + if not isinstance(spawn.find_executable('pdfcrop'),type(None)): |
| 169 | + # Here is a bug in pdfcrop, no idea how to fix. |
| 170 | + crop_cmd = 'pdfcrop "%s"' % pdf_file |
| 171 | + crop = subprocess.Popen(crop_cmd, |
| 172 | + stdout=subprocess.PIPE, |
| 173 | + stderr=subprocess.PIPE, |
| 174 | + shell=True) |
| 175 | + out = crop.communicate() |
| 176 | + if len(out[1]) > 0: |
| 177 | + inkex.errormsg("Error in pdfcrop:") |
| 178 | + inkex.errormsg(" CMD executed: %s" % crop_cmd) |
| 179 | + for msg in out: |
| 180 | + inkex.errormsg(msg) |
| 181 | + inkex.errormsg("Process will continue without crop") |
| 182 | + |
| 183 | + if os.path.exists(crop_file): |
| 184 | + os.remove(pdf_file) |
| 185 | + os.rename(crop_file, pdf_file) |
184 | 186 | except: |
185 | 187 | pass |
186 | 188 |
|
|
0 commit comments