From 9747f27d3124debc91ad149fd9d8c138f4e8e0d0 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 7 Feb 2016 17:11:00 +0530 Subject: [PATCH] run pdftotext only once --- oml/media/pdf.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/oml/media/pdf.py b/oml/media/pdf.py index 5238685..b370525 100644 --- a/oml/media/pdf.py +++ b/oml/media/pdf.py @@ -229,18 +229,19 @@ def info(pdf): ''' def extract_text(pdf): + if sys.platform == 'win32': + pdf = get_short_path_name(pdf) if sys.platform == 'darwin': cmd = ['/usr/bin/mdimport', '-d2', pdf] else: - if sys.platform == 'win32': - pdf = get_short_path_name(pdf) cmd = ['pdftotext', pdf, '-'] if sys.platform == 'win32': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() stdout = stdout.decode() stderr = stderr.decode()