Skip to content

Commit 287e682

Browse files
committed
Merge branch 'pdf_crop'
2 parents 3a04551 + ba70252 commit 287e682

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

writetex.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sys
1919
import copy
2020
import subprocess
21+
from distutils import spawn
2122
WriteTexNS = u'http://wanglongqi.github.io/WriteTeX'
2223
# from textext
2324
SVG_NS = u"http://www.w3.org/2000/svg"
@@ -164,23 +165,24 @@ def effect(self):
164165
tmp_dir=tmp_dir, tex_file=tex_file, out_file=out_file), shell=True)
165166

166167
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)
184186
except:
185187
pass
186188

0 commit comments

Comments
 (0)