from __future__ import annotations
import io
from typing import List, Iterator, Tuple, Optional, Any, TYPE_CHECKING, Callable
from ctypes import *
from datetime import datetime
from numbers import Number
from pdftools_sdk.internal import _lib
from pdftools_sdk.internal.utils import _string_to_utf16, _utf16_to_string
from pdftools_sdk.internal.streams import _StreamDescriptor, _NativeStream
from pdftools_sdk.internal.native_base import _NativeBase
from pdftools_sdk.internal.native_object import _NativeObject
import pdftools_sdk.internal
if TYPE_CHECKING:
from pdftools_sdk.ocr.image_processing_mode import ImageProcessingMode
else:
ImageProcessingMode = "pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode"
[docs]
class ImageOptions(_NativeObject):
"""
Options for OCR processing of images
These options control how images in the PDF document are processed during OCR.
"""
[docs]
def __init__(self):
"""
"""
_lib.PdfToolsOcr_ImageOptions_New.argtypes = []
_lib.PdfToolsOcr_ImageOptions_New.restype = c_void_p
ret_val = _lib.PdfToolsOcr_ImageOptions_New()
if ret_val is None:
_NativeBase._throw_last_error(False)
super()._initialize(ret_val)
@property
def mode(self) -> ImageProcessingMode:
"""
The mode for processing images
Default value: :attr:`pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode.NONE`
Returns:
pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode
"""
from pdftools_sdk.ocr.image_processing_mode import ImageProcessingMode
_lib.PdfToolsOcr_ImageOptions_GetMode.argtypes = [c_void_p]
_lib.PdfToolsOcr_ImageOptions_GetMode.restype = c_int
ret_val = _lib.PdfToolsOcr_ImageOptions_GetMode(self._handle)
if ret_val == 0:
_NativeBase._throw_last_error()
return ImageProcessingMode(ret_val)
@mode.setter
def mode(self, val: ImageProcessingMode) -> None:
"""
The mode for processing images
Default value: :attr:`pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode.NONE`
Args:
val (pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode):
property value
"""
from pdftools_sdk.ocr.image_processing_mode import ImageProcessingMode
if not isinstance(val, ImageProcessingMode):
raise TypeError(f"Expected type {ImageProcessingMode.__name__}, but got {type(val).__name__}.")
_lib.PdfToolsOcr_ImageOptions_SetMode.argtypes = [c_void_p, c_int]
_lib.PdfToolsOcr_ImageOptions_SetMode.restype = c_bool
if not _lib.PdfToolsOcr_ImageOptions_SetMode(self._handle, c_int(val.value)):
_NativeBase._throw_last_error(False)
@property
def rotate_scan(self) -> bool:
"""
Whether to rotate scanned pages based on detected orientation
This option has an effect only if the required information is provided by the OCR engine,
which depends on the type and settings of the engine.
Default value: `False`
Returns:
bool
"""
_lib.PdfToolsOcr_ImageOptions_GetRotateScan.argtypes = [c_void_p]
_lib.PdfToolsOcr_ImageOptions_GetRotateScan.restype = c_bool
ret_val = _lib.PdfToolsOcr_ImageOptions_GetRotateScan(self._handle)
if not ret_val:
_NativeBase._throw_last_error()
return ret_val
@rotate_scan.setter
def rotate_scan(self, val: bool) -> None:
"""
Whether to rotate scanned pages based on detected orientation
This option has an effect only if the required information is provided by the OCR engine,
which depends on the type and settings of the engine.
Default value: `False`
Args:
val (bool):
property value
"""
if not isinstance(val, bool):
raise TypeError(f"Expected type {bool.__name__}, but got {type(val).__name__}.")
_lib.PdfToolsOcr_ImageOptions_SetRotateScan.argtypes = [c_void_p, c_bool]
_lib.PdfToolsOcr_ImageOptions_SetRotateScan.restype = c_bool
if not _lib.PdfToolsOcr_ImageOptions_SetRotateScan(self._handle, val):
_NativeBase._throw_last_error(False)
@property
def deskew_scan(self) -> bool:
"""
Whether to deskew scanned pages
This option has an effect only if the required information is provided by the OCR engine,
which depends on the type and settings of the engine.
Default value: `False`
Returns:
bool
"""
_lib.PdfToolsOcr_ImageOptions_GetDeskewScan.argtypes = [c_void_p]
_lib.PdfToolsOcr_ImageOptions_GetDeskewScan.restype = c_bool
ret_val = _lib.PdfToolsOcr_ImageOptions_GetDeskewScan(self._handle)
if not ret_val:
_NativeBase._throw_last_error()
return ret_val
@deskew_scan.setter
def deskew_scan(self, val: bool) -> None:
"""
Whether to deskew scanned pages
This option has an effect only if the required information is provided by the OCR engine,
which depends on the type and settings of the engine.
Default value: `False`
Args:
val (bool):
property value
"""
if not isinstance(val, bool):
raise TypeError(f"Expected type {bool.__name__}, but got {type(val).__name__}.")
_lib.PdfToolsOcr_ImageOptions_SetDeskewScan.argtypes = [c_void_p, c_bool]
_lib.PdfToolsOcr_ImageOptions_SetDeskewScan.restype = c_bool
if not _lib.PdfToolsOcr_ImageOptions_SetDeskewScan(self._handle, val):
_NativeBase._throw_last_error(False)
@property
def remove_only_invisible_ocr_text(self) -> bool:
"""
Whether to remove only invisible OCR text (text rendering mode 3)
When used with :attr:`pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode.REPLACETEXT`
or :attr:`pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode.REMOVETEXT` , only the invisible text layer
typically added by OCR engines is removed, while other text is preserved.
Default value: `False`
Returns:
bool
"""
_lib.PdfToolsOcr_ImageOptions_GetRemoveOnlyInvisibleOcrText.argtypes = [c_void_p]
_lib.PdfToolsOcr_ImageOptions_GetRemoveOnlyInvisibleOcrText.restype = c_bool
ret_val = _lib.PdfToolsOcr_ImageOptions_GetRemoveOnlyInvisibleOcrText(self._handle)
if not ret_val:
_NativeBase._throw_last_error()
return ret_val
@remove_only_invisible_ocr_text.setter
def remove_only_invisible_ocr_text(self, val: bool) -> None:
"""
Whether to remove only invisible OCR text (text rendering mode 3)
When used with :attr:`pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode.REPLACETEXT`
or :attr:`pdftools_sdk.ocr.image_processing_mode.ImageProcessingMode.REMOVETEXT` , only the invisible text layer
typically added by OCR engines is removed, while other text is preserved.
Default value: `False`
Args:
val (bool):
property value
"""
if not isinstance(val, bool):
raise TypeError(f"Expected type {bool.__name__}, but got {type(val).__name__}.")
_lib.PdfToolsOcr_ImageOptions_SetRemoveOnlyInvisibleOcrText.argtypes = [c_void_p, c_bool]
_lib.PdfToolsOcr_ImageOptions_SetRemoveOnlyInvisibleOcrText.restype = c_bool
if not _lib.PdfToolsOcr_ImageOptions_SetRemoveOnlyInvisibleOcrText(self._handle, val):
_NativeBase._throw_last_error(False)
@staticmethod
def _create_dynamic_type(handle):
return ImageOptions._from_handle(handle)
@classmethod
def _from_handle(cls, handle):
"""
Internal factory method for constructing an instance using an internal handle.
This method creates an instance of the class by bypassing the public constructor.
"""
instance = ImageOptions.__new__(cls) # Bypass __init__
instance._initialize(handle)
return instance
def _initialize(self, handle):
super()._initialize(handle)