diff --git a/docs/pipeline.svg b/docs/pipeline.svg index 8361bba4..d21f4ef0 100644 --- a/docs/pipeline.svg +++ b/docs/pipeline.svg @@ -17,440 +17,440 @@ t0 - - - - -ocrmypdf.pipeline.triage + + + + +ocrmypdf.pipeline.triage t1 - - - - -ocrmypdf.pipeline.repair_and_parse_pdf + + + + +ocrmypdf.pipeline.repair_and_parse_pdf t0->t1 - - + + t2 - - -ocrmypdf.pipeline.marker_pages + + +ocrmypdf.pipeline.marker_pages t1->t2 - - + + - + t17 - - - - -ocrmypdf.pipeline.weave_layers + + + + +ocrmypdf.pipeline.weave_layers - + t1->t17 - - + + - + t18 - - - - -ocrmypdf.pipeline.generate_postscript_stub + + + + +ocrmypdf.pipeline.generate_postscript_stub - + t1->t18 - - + + - + t20 - - -ocrmypdf.pipeline.metadata_fixup + + +ocrmypdf.pipeline.metadata_fixup - + t1->t20 - - + + - + t21 - - -ocrmypdf.pipeline.merge_pages + + +ocrmypdf.pipeline.merge_pages - + t1->t21 - - + + t3 - - -ocrmypdf.pipeline.ocr_or_skip + + +ocrmypdf.pipeline.ocr_or_skip t2->t3 - - + + t4 - - - - -ocrmypdf.pipeline.rasterize_preview + + + + +ocrmypdf.pipeline.rasterize_preview t3->t4 - - + + t5 - - - - -ocrmypdf.pipeline.orient_page + + + + +ocrmypdf.pipeline.orient_page t3->t5 - - + + t4->t5 - - + + t6 - - - - -ocrmypdf.pipeline.rasterize_with_ghostscript + + + + +ocrmypdf.pipeline.rasterize_with_ghostscript t5->t6 - - - - - -t16 - - - - -ocrmypdf.pipeline.ocr_tesseract_textonly_pdf - - - -t5->t16 - - + + - + t13 - -ocrmypdf.pipeline.select_image_layer + +ocrmypdf.pipeline.select_image_layer - + t5->t13 - - + + - + t19 - - - - -ocrmypdf.pipeline.skip_page + + + + +ocrmypdf.pipeline.skip_page - + t5->t19 - - + + t7 - - - - -ocrmypdf.pipeline.preprocess_remove_background + + + + +ocrmypdf.pipeline.preprocess_remove_background t6->t7 - - + + - + t12 - -ocrmypdf.pipeline.select_visible_page_image + +ocrmypdf.pipeline.select_visible_page_image - + t6->t12 - - + + t8 - - - - -ocrmypdf.pipeline.preprocess_deskew + + + + +ocrmypdf.pipeline.preprocess_deskew t7->t8 - - + + - + t7->t12 - - + + t9 - - - - -ocrmypdf.pipeline.preprocess_clean + + + + +ocrmypdf.pipeline.preprocess_clean t8->t9 - - + + - + t8->t12 - - + + t10 - - - - -ocrmypdf.pipeline.select_ocr_image + + + + +ocrmypdf.pipeline.select_ocr_image t9->t10 - - + + - + t9->t12 - - + + t11 - - - - -ocrmypdf.pipeline.ocr_tesseract_hocr + + + + +ocrmypdf.pipeline.ocr_tesseract_hocr t10->t11 - - + + + + + +t16 + + + + +ocrmypdf.pipeline.ocr_tesseract_textonly_pdf - -t10->t16 - - - - - -t14 - - - - -ocrmypdf.pipeline.render_hocr_page - - -t11->t14 - - - - - -t15 - - - - -ocrmypdf.pipeline.render_hocr_debug_page - - - -t11->t15 - - +t10->t16 + + - + t22 - - -ocrmypdf.pipeline.merge_sidecars + + +ocrmypdf.pipeline.merge_sidecars - + t11->t22 - - + + - - -t14->t17 - - + + +t14 + + + + +ocrmypdf.pipeline.render_hocr_page - - -t16->t17 - - + + +t11->t14 + + + + + +t15 + + + + +ocrmypdf.pipeline.render_hocr_debug_page + + + +t11->t15 + + - + t16->t22 - - + + + + + +t16->t17 + + + + + +t14->t17 + + - + t12->t13 - - + + - + t12->t15 - - + + - + t13->t17 - - + + - + t17->t20 - - + + - - -t18->t20 - - - - - -t18->t21 - - - - - -t23 - - -ocrmypdf.pipeline.copy_final - - - -t20->t23 - - + + +t15->t20 + + - + t15->t21 - - + + + + + +t18->t20 + + + + + +t18->t21 + + + + + +t23 + + +ocrmypdf.pipeline.copy_final + + + +t20->t23 + + - + t19->t21 - - + + - + t21->t23 - - + + diff --git a/src/ocrmypdf/__main__.py b/src/ocrmypdf/__main__.py index 2d0a0a0c..ad975b16 100755 --- a/src/ocrmypdf/__main__.py +++ b/src/ocrmypdf/__main__.py @@ -874,7 +874,7 @@ def run_pipeline(): except ExitCodeException as e: return e.exit_code except Exception as e: - _log.error(e) + _log.error(str(e)) return ExitCode.other_error if options.flowchart: diff --git a/src/ocrmypdf/exec/tesseract.py b/src/ocrmypdf/exec/tesseract.py index 64dfb2ae..dde25b4a 100644 --- a/src/ocrmypdf/exec/tesseract.py +++ b/src/ocrmypdf/exec/tesseract.py @@ -282,18 +282,19 @@ def use_skip_page(text_only, skip_pdf, output_pdf, output_text): with open(output_text, 'w') as f: f.write('[skipped page]') - if not text_only: + if skip_pdf and not text_only: + # Substitute a "skipped page" with suppress(FileNotFoundError): os.remove(output_pdf) # In case it was partially created os.symlink(skip_pdf, output_pdf) return - # For text only we must create an empty file + # Or normally, just write a 0 byte file to the output to indicate a skip with open(output_pdf, 'wb') as out: out.write(b'') -def generate_pdf(*, input_image, skip_pdf, output_pdf, output_text, +def generate_pdf(*, input_image, skip_pdf=None, output_pdf, output_text, language: list, engine_mode, text_only: bool, tessconfig: list, timeout: float, pagesegmode: int, user_words, user_patterns, log): diff --git a/src/ocrmypdf/pipeline.py b/src/ocrmypdf/pipeline.py index 61846147..e89e91ba 100644 --- a/src/ocrmypdf/pipeline.py +++ b/src/ocrmypdf/pipeline.py @@ -817,8 +817,6 @@ def weave_layers( # or fitz # - # Consider removing ocr_tesseract_and_render_pdf as it becomes too special - from itertools import groupby import pikepdf @@ -948,14 +946,13 @@ def ocr_tesseract_textonly_pdf( input_image = next((ii for ii in infiles if ii.endswith('.ocr.png')), '') if not input_image: raise ValueError("No image rendered?") - skip_pdf = next((ii for ii in infiles if ii.endswith('.pdf'))) output_pdf = next((ii for ii in outfiles if ii.endswith('.pdf'))) output_text = next((ii for ii in outfiles if ii.endswith('.txt'))) tesseract.generate_pdf( input_image=input_image, - skip_pdf=skip_pdf, # only needs dimensions of skip page + skip_pdf=None, output_pdf=output_pdf, output_text=output_text, language=options.language, @@ -1396,8 +1393,8 @@ def build_pipeline(options, work_folder, log, context): # Tesseract OCR + text only PDF task_ocr_tesseract_textonly_pdf = main_pipeline.collate( task_func=ocr_tesseract_textonly_pdf, - input=[task_select_ocr_image, task_orient_page], - filter=regex(r".*/(\d{6})(?:\.ocr.png|\.ocr\.oriented\.pdf)"), + input=[task_select_ocr_image], + filter=regex(r".*/(\d{6})(?:\.ocr.png)"), output=[os.path.join(work_folder, r'\1.text.pdf'), os.path.join(work_folder, r'\1.text.txt')], extras=[log, context]) @@ -1439,6 +1436,7 @@ def build_pipeline(options, work_folder, log, context): task_func=metadata_fixup, input=[task_repair_and_parse_pdf, task_weave_layers, + task_render_hocr_debug_page, task_generate_postscript_stub], output=os.path.join(work_folder, 'metafix.pdf'), extras=[log, context]