Make the go/no-go decision pluggable
This commit is contained in:
@@ -160,6 +160,12 @@ def validate_pdfinfo_options(context):
|
||||
pdfinfo = context.pdfinfo
|
||||
options = context.options
|
||||
|
||||
if options.plugin_validation:
|
||||
validate = load_plugin(options.plugin_validation)
|
||||
result = validate(context)
|
||||
if result is not None:
|
||||
return result
|
||||
|
||||
if pdfinfo.needs_rendering:
|
||||
log.error(
|
||||
"This PDF contains dynamic XFA forms created by Adobe LiveCycle "
|
||||
|
||||
+4
-1
@@ -119,7 +119,9 @@ def create_options(*, input_file, output_file, **kwargs):
|
||||
for arg, val in kwargs.items():
|
||||
if val is None:
|
||||
continue
|
||||
if arg.startswith('filter') and (callable(val) or isinstance(val, str)):
|
||||
if (arg.startswith('plugin') or arg.startswith('filter')) and (
|
||||
callable(val) or isinstance(val, str)
|
||||
):
|
||||
deferred.append((arg, val))
|
||||
continue
|
||||
elif arg == 'tesseract_env':
|
||||
@@ -199,6 +201,7 @@ def ocrmypdf( # pylint: disable=unused-argument
|
||||
keep_temporary_files=None,
|
||||
progress_bar=None,
|
||||
filter_ocr_image=None,
|
||||
plugin_validation=None,
|
||||
tesseract_env=None,
|
||||
):
|
||||
"""Run OCRmyPDF on one PDF or image.
|
||||
|
||||
+5
-2
@@ -468,10 +468,13 @@ advanced.add_argument(
|
||||
help="Specify the location of the Tesseract user patterns file.",
|
||||
)
|
||||
|
||||
filters = parser.add_argument_group("Filters", argparse.SUPPRESS)
|
||||
filters.add_argument(
|
||||
plugins = parser.add_argument_group("Filters and Plugins", argparse.SUPPRESS)
|
||||
plugins.add_argument(
|
||||
'--filter-ocr-image', help=argparse.SUPPRESS, type=check_plugin_loadable
|
||||
)
|
||||
plugins.add_argument(
|
||||
'--plugin-validation', help=argparse.SUPPRESS, type=check_plugin_loadable
|
||||
)
|
||||
|
||||
debugging = parser.add_argument_group(
|
||||
"Debugging", "Arguments to help with troubleshooting and debugging"
|
||||
|
||||
@@ -185,7 +185,7 @@ class LTStateAwareChar(LTChar):
|
||||
|
||||
def get_text(self):
|
||||
if isinstance(self._text, tuple):
|
||||
return '�'
|
||||
return '\ufffd' # standard 'Unknown symbol'
|
||||
return self._text
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
Reference in New Issue
Block a user