Bug in tesseract_noop spoof: produced wrong page sizes

Now checks input image to ensure the implied page size of its .hocr file
matches the rest of the PDF.
This commit is contained in:
James R. Barlow
2016-02-04 18:48:22 -08:00
parent ccfbb54e8c
commit 43b0faa830
+6 -2
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import sys
import img2pdf
from PIL import Image
VERSION_STRING = '''tesseract 3.04.00
@@ -40,9 +41,12 @@ def main():
print('List of available languages (1):\neng', file=sys.stderr)
sys.exit(0)
elif sys.argv[-1] == 'hocr':
inputf = sys.argv[-3]
output = sys.argv[-2]
with open(output + '.hocr', 'w', encoding='utf-8') as f:
f.write(HOCR_TEMPLATE.format('1000', '1000'))
with Image.open(inputf) as im, \
open(output + '.hocr', 'w', encoding='utf-8') as f:
w, h = im.size
f.write(HOCR_TEMPLATE.format(str(w), str(h)))
elif sys.argv[-1] == 'pdf':
inputf = sys.argv[-3]
output = sys.argv[-2]