
    TAi                         % S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SS	K
Jr  SS
KJr  \\	\S.r\\\\   4   \S'    " S S\5      r " S S5      rg)z>Classes and functions for the ImageConversionBackend backends.    )Any)Dict)List)Type   )ConversionBackend)GhostscriptBackend)PdfiumBackend)PopplerBackend)pdfiumghostscriptpopplerBACKENDSc                       \ rS rSrSrg)ImageConversionError    N)__name__
__module____qualname____firstlineno____static_attributes__r       ]/var/www/html/land-ocr/venv/lib/python3.13/site-packages/camelot/backends/image_conversion.pyr   r      s    r   r   c                   N    \ rS rSrSrSS\S\SS4S jjrS rS	\	S
\	SS4S jr
Srg)ImageConversionBackend   z+Classes the ImageConversionBackend backend.backenduse_fallbackreturnNc                    ^ U R                  T5      U l        X l        [        [	        U4S j[
        R                  5       5      5      U l        g)a5  Initialize the conversion backend .

Parameters
----------
backend : Any, optional
    Backend for image conversion, by default "pdfium"
use_fallback : bool, optional
    Fallback to another backend if unavailable, by default True

Raises
------
ValueError
    Raise an error if the backend is not supported.
c                 <   > [        T[        5      =(       a    U T:g  $ )N)
isinstancestr)xr   s    r   <lambda>1ImageConversionBackend.__init__.<locals>.<lambda>.   s    Z5F!w,Fr   N)get_backendr   r   listfilterr   keys	fallbacks)selfr   r   s    ` r   __init__ImageConversionBackend.__init__   s:     +/*:*:7*C".$(FX%
r   c                    ^ U4S jn[        T[        5      (       a6  T[        R                  5       ;  a  [	        ST< S35      e[        T   " 5       $ U" 5       (       d  [	        T< S35      eT$ )a  Retrieve the specified backend for processing.

This method checks if the provided backend is a string representing
a known backend or an object implementing a 'convert' method. It
returns an instance of the backend if valid.

Parameters
----------
backend : str or object
    The backend to retrieve. This can be:
        - A string ('poppler' or 'ghostscript') corresponding to a pre-defined backend.
        - An object that must implement a 'convert' method.

Returns
-------
object
    An instance of the specified backend.

Raises
------
NotImplementedError
    If the backend is a string that is not recognized or if it is an
    object that does not implement the 'convert' method.

Examples
--------
>> backend_instance = get_backend('poppler')
>> backend_instance = get_backend(my_custom_backend)

Notes
-----
The valid backends are defined in the BACKENDS dictionary. The
method verifies the backend type and raises exceptions for
unsupported backends.
c                  x   > [        T5       V s/ s H  o R                  S5      SL d  M  U PM     nn SU;   $ s  sn f )N__Fconvert)dir
startswith)methodmethodsr   s     r   implements_convert>ImageConversionBackend.get_backend.<locals>.implements_convertV   sF    %(\%165F5Ft5LPU5U\   ''s   77zUnknown backend z< specified. Please use 'pdfium', 'poppler' or 'ghostscript'.z" must implement a 'convert' method)r#   r$   r   r+   NotImplementedError)r-   r   r8   s    ` r   r(   "ImageConversionBackend.get_backend1   sx    J	( gs##hmmo-)&wk1mn  G$&&%'')k!CD  Nr   pdf_pathpng_pathc                     U R                   R                  X5        g! [         a  nU R                  (       ac  U R                   HN  n [
        U   " 5       nUR                  X5           SnAg! [         a  nSU< SU 3n[        U5      UeSnAff = f    SnAgSU R                   < SU 3n[        U5      UeSnAff = f)zConvert PDF to png_path.

Parameters
----------
pdf_path : str
    Path where to read the pdf file.
png_path : str
    Path where to save png file.

Raises
------
type
    [description]
type
    [description]
z6Image conversion failed with image conversion backend z	
 error: N)r   r3   	Exceptionr   r,   r   r   )r-   r<   r=   ffallback	converteremsgs           r   r3   ImageConversionBackend.convertk   s    "	7LL  4 	7   $H$,X$6$8	!))(=
 	 % ? VW_Vbblmnlop237Q>?	 !/ Ot||N^^hijhkl*3/Q6	7s>    
C  B;	A.(B;.
B8BBB;B;;C )r   r,   r   )r   T)r   r   r   r   __doc__r   boolr.   r(   r$   r3   r   r   r   r   r   r      s?    5
 
d 
d 
*8t 7  7s  7t  7r   r   N)rF   typingr   r   r   r   baser   ghostscript_backendr	   pdfium_backendr
   poppler_backendr   r   r$   __annotations__
ValueErrorr   r   r   r   r   <module>rO      sa    D     # 3 ) + %0$sD*++
, 	: 	r7 r7r   