diff --git a/src/ocrmypdf/hocrtransform/__init__.py b/src/ocrmypdf/hocrtransform/__init__.py index 72c6ea74..7dce171a 100755 --- a/src/ocrmypdf/hocrtransform/__init__.py +++ b/src/ocrmypdf/hocrtransform/__init__.py @@ -5,8 +5,6 @@ from __future__ import annotations -import argparse - from ocrmypdf.hocrtransform._hocr import ( DebugRenderOptions, HocrTransform, @@ -18,35 +16,3 @@ __all__ = ( 'HocrTransformError', 'DebugRenderOptions', ) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Convert hocr file to PDF') - parser.add_argument( - '-b', - '--boundingboxes', - action="store_true", - default=False, - help='Show bounding boxes borders', - ) - parser.add_argument( - '-r', - '--resolution', - type=int, - default=300, - help='Resolution of the image that was OCRed', - ) - parser.add_argument( - '-i', - '--image', - default=None, - help='Path to the image to be placed above the text', - ) - parser.add_argument('hocrfile', help='Path to the hocr file to be parsed') - parser.add_argument('outputfile', help='Path to the PDF file to be generated') - args = parser.parse_args() - - hocr = HocrTransform(hocr_filename=args.hocrfile, dpi=args.resolution) - hocr.to_pdf( - out_filename=args.outputfile, - image_filename=args.image, - ) diff --git a/src/ocrmypdf/hocrtransform/__main__.py b/src/ocrmypdf/hocrtransform/__main__.py new file mode 100644 index 00000000..3877916a --- /dev/null +++ b/src/ocrmypdf/hocrtransform/__main__.py @@ -0,0 +1,40 @@ +# SPDX-FileCopyrightText: 2023 James R. Barlow +# SPDX-License-Identifier: MIT + +"""Simple CLI for testing HOCR.""" + +import argparse + +from ocrmypdf.hocrtransform import HocrTransform + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Convert hocr file to PDF') + parser.add_argument( + '-b', + '--boundingboxes', + action="store_true", + default=False, + help='Show bounding boxes borders', + ) + parser.add_argument( + '-r', + '--resolution', + type=int, + default=300, + help='Resolution of the image that was OCRed', + ) + parser.add_argument( + '-i', + '--image', + default=None, + help='Path to the image to be placed above the text', + ) + parser.add_argument('hocrfile', help='Path to the hocr file to be parsed') + parser.add_argument('outputfile', help='Path to the PDF file to be generated') + args = parser.parse_args() + + hocr = HocrTransform(hocr_filename=args.hocrfile, dpi=args.resolution) + hocr.to_pdf( + out_filename=args.outputfile, + image_filename=args.image, + ) diff --git a/tests/test_hocrtransform.py b/tests/test_hocrtransform.py index 354cd04d..edde6dfe 100644 --- a/tests/test_hocrtransform.py +++ b/tests/test_hocrtransform.py @@ -4,7 +4,6 @@ from __future__ import annotations import re -import shutil from io import StringIO import pytest