Fix hocrtransform CLI

This commit is contained in:
James R. Barlow
2023-12-02 08:08:29 -08:00
parent aacaba3d26
commit 11d3e32f1e
3 changed files with 40 additions and 35 deletions
-34
View File
@@ -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,
)
+40
View File
@@ -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,
)
-1
View File
@@ -4,7 +4,6 @@
from __future__ import annotations
import re
import shutil
from io import StringIO
import pytest