Implement pdf renderer side of tess spoof

This commit is contained in:
James R. Barlow
2015-12-17 11:41:54 -08:00
parent 45113676a3
commit 7313a77c2a
2 changed files with 11 additions and 4 deletions
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import sys
import img2pdf
VERSION_STRING = '''tesseract 3.04.00
@@ -42,6 +43,12 @@ def main():
output = sys.argv[-2]
with open(output + '.hocr', 'w', encoding='utf-8') as f:
f.write(HOCR_TEMPLATE.format('1000', '1000'))
elif sys.argv[-1] == 'pdf':
inputf = sys.argv[-3]
output = sys.argv[-2]
pdf_bytes = img2pdf.convert([inputf], dpi=300)
with open(output + '.pdf', 'wb') as f:
f.write(pdf_bytes)
else:
print("Spoof doesn't understand arguments", file=sys.stderr)
print(sys.argv, file=sys.stderr)
+4 -4
View File
@@ -83,18 +83,18 @@ def test_quick():
@pytest.fixture
def spoof_tesseract_hocr_empty():
def spoof_tesseract_noop():
env = os.environ.copy()
program = os.path.join(SPOOF_PATH, 'tesseract_hocr_empty.py')
program = os.path.join(SPOOF_PATH, 'tesseract_noop.py')
check_call(['chmod', "+x", program])
env['OCRMYPDF_TESSERACT'] = program
return env
def test_deskew(spoof_tesseract_hocr_empty):
def test_deskew(spoof_tesseract_noop):
# Run with deskew
deskewed_pdf = check_ocrmypdf(
'skew.pdf', 'test_deskew.pdf', '-d', env=spoof_tesseract_hocr_empty)
'skew.pdf', 'test_deskew.pdf', '-d', env=spoof_tesseract_noop)
# Now render as an image again and use Leptonica to find the skew angle
# to confirm that it was deskewed