Fix issue #194 - --sidecar creates blank txt file

This commit is contained in:
James R. Barlow
2017-10-26 18:15:31 -07:00
parent 9fd165bf4b
commit 7f1cd1444b
3 changed files with 23 additions and 5 deletions
+6
View File
@@ -5,6 +5,12 @@ OCRmyPDF uses `semantic versioning <http://semver.org/>`_ for its command line i
The OCRmyPDF package itself does not contain a public API, although it is fairly stable and breaking changes are usually timed with a major release. A future release will clearly define the stable public API.
v5.4.2
------
- Fixed a regression from v5.4.1 that caused sidecar files to be created as empty files
v5.4.1
------
+4 -4
View File
@@ -945,7 +945,7 @@ def merge_sidecars(
if page_num != 0:
stream.write('\f') # Form feed between pages
if txt_file:
with open(txt_file, 'r') as in_:
with open(txt_file, 'r', encoding="utf-8") as in_:
txt = in_.read()
# Tesseract v4 alpha started adding form feeds in
# commit aa6eb6b
@@ -953,9 +953,9 @@ def merge_sidecars(
# for consistency just ignore its form feeds and insert our
# own
if txt.endswith('\f'):
stream.write(in_.read()[:-1])
stream.write(txt[:-1])
else:
stream.write(in_.read())
stream.write(txt)
else:
stream.write('[OCR skipped on page {}]'.format(
page_num + 1))
@@ -964,7 +964,7 @@ def merge_sidecars(
write_pages(sys.stdout)
sys.stdout.flush()
else:
with open(output_file, 'w', encoding='utf-8') as out:
with open(output_file, 'w', encoding="utf-8") as out:
write_pages(out)
+13 -1
View File
@@ -805,7 +805,6 @@ def test_user_words(resources, outdir):
'--image-dpi', 150,
'--sidecar', sidecar_before
)
assert 'cromulent' not in sidecar_before.open().read()
with word_list.open('w') as f:
@@ -984,6 +983,19 @@ def test_sidecar_pagecount(spoof_tesseract_cache, resources, outpdf):
"Sidecar page count does not match PDF page count"
def test_sidecar_nonempty(spoof_tesseract_cache, resources, outpdf):
sidecar = outpdf + '.txt'
check_ocrmypdf(
resources / 'ccitt.pdf', outpdf,
'--sidecar', sidecar,
env=spoof_tesseract_cache
)
with open(sidecar, 'r') as f:
ocr_text = f.read()
assert 'the' in ocr_text
def test_pdfa_1(spoof_tesseract_cache, resources, outpdf):
check_ocrmypdf(
resources / 'ccitt.pdf', outpdf,