First cut at improving text extraction speed

This commit is contained in:
James R. Barlow
2018-09-16 23:34:18 -07:00
parent eaf772f80a
commit 4615cf2f1e
3 changed files with 43 additions and 30 deletions
+10 -3
View File
@@ -64,10 +64,18 @@ def extract_text(input_file, pageno=1):
<span bbox="left top right bottom" font="..." size="...">
<char bbox="...." c="X"/>
:param pageno: number of page to extract, or all pages if None
:return: XML-ish text representation in bytes
"""
if pageno is not None:
pages = [
'-dFirstPage=%i' % pageno,
'-dLastPage=%i' % pageno
]
else:
pages = []
args_gs = [
'gs',
'-dQUIET',
@@ -76,8 +84,7 @@ def extract_text(input_file, pageno=1):
'-dNOPAUSE',
'-sDEVICE=txtwrite',
'-dTextFormat=0',
'-dFirstPage=%i' % pageno,
'-dLastPage=%i' % pageno,
] + pages + [
'-o', '-',
input_file
]