
    )iB`              0       :   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJrJ	r	  SSK
JrJrJrJrJrJr  SSKJr  SSKJr  SSKJrJrJr  SSKJrJrJrJr  SS	KJrJ r J!r!J"r"  S
S/r#S/r$SSSSSSSSSSSSS\" 5       SSSSSSS4S\\%\4   S\&S\\%\4   S\&S\&S\%S\S\&S\%S\%S\'S\'S\'S\'S\S \\%\4   S!\'S"\\\&4   S#\'S$\'S%\&S&\'S'\\R(                     4.S( jjr(SSSSSSSSSSSSS\" 5       SSSSSSS4S)\)S\&S\\%\4   S\&S\&S\%S\S\&S\%S\%S\'S\'S\'S\'S\\%\4   S \\%\4   S!\'S"\\\&4   S#\'S$\'S%\&S&\'S'\\R(                     4.S* jjr*S+\S\%S\&S\&S\%S\S\%S\%S\%S\'S\'S\'S!\'S"\\&\\&\&4   4   S&\'S'\\%   4 S, jr+S9S\%S!\'S'\\%\%\\'4   4S- jjr,S\S'\%4S. jr-S:S/\%S \%S'\%4S0 jjr. S;S/\%S \%S%\&S'\\&\&4   4S1 jjr/       S<S\%S\%S\%S \%S2\'S%\&S\&S\&S'\4S3 jjr0       S<S4\)S\%S\%S \%S2\'S%\&S\&S\&S'\4S5 jjr1 S9S\%S\%S6\%S#\'S7\'S'\\R(                     4S8 jjr2g)=zi
pdf2image is a light wrapper for the poppler-utils tools that can convert your
PDFs into Pillow images.
    N)PopenPIPETimeoutExpired)AnyUnionTupleListDictCallable)PurePath)Image)uuid_generatorcounter_generatorThreadSafeGenerator)parse_buffer_to_pgmparse_buffer_to_ppmparse_buffer_to_jpegparse_buffer_to_png)PDFInfoNotInstalledErrorPDFPageCountErrorPDFSyntaxErrorPDFPopplerTimeoutErrorpngtiffPages   ppm   Fpdf_pathdpioutput_folder
first_page	last_pagefmtjpegoptthread_countuserpwownerpwuse_cropboxstricttransparentsingle_fileoutput_filepoppler_path	grayscalesize
paths_onlyuse_pdftocairotimeouthide_annotationsreturnc                    U(       a  US:X  a  Sn[        U [        5      (       a  U R                  5       n [        U[        5      (       a  UR                  5       n[        U[        5      (       a  UR                  5       n[        XXS9S   n[	        UU5      u  nnnnU=(       d    U=(       d    U=(       a	    U[
        ;   n[        U(       a  SOSUS9u  nnUS:X  a  US::  a  S	nUS:X  a  US
::  a  Sn[        U[        R                  5      (       d6  [        U[        5      (       d!  U(       a  [        U/5      nSnO[        U5      nUS:  a  SnUb  US:  a  SnUb  UU:  a  UnX4:  a  / $  SnUc  U(       a  [        R                  " 5       nSnXC-
  S-   nUU:  a  UnUU-  nUn / n![        U5       GHS  n"[        U5      n#UU-  [!        US:  5      -   n$[#        S[%        U5      U /UU U U$-   S-
  UUU#UU	U
UUUUU5      n%U(       a#  U(       a  ['        S5      e[)        SU5      /U%-   n%O[)        SU5      /U%-   n%U U$-   n U[!        US:  5      -  n[*        R,                  R/                  5       n&Ub  US-   U&R1                  SS5      -   U&S'   S	n'[2        R4                  " 5       S:X  a8  [6        R8                  " 5       n'U'=R:                  [6        R<                  -  sl        U!R?                  U#[A        U%U&[B        [B        U'S945        GMV     / n(U! Ha  u  n)n* U*RE                  US9u  n+n,SU,;   a"  U(       a  [M        U,RO                  SS5      5      eUb  U([Q        UU)UUUS9-  n(MV  U(U" U+5      -  n(Mc     U(       a  [R        RT                  " U5        U($ ! [F         a/    U*RI                  5         U*RE                  5       u  n-n.[K        S5      ef = f! W(       a  [R        RT                  " U5        f f = f)a  Function wrapping pdftoppm and pdftocairo

:param pdf_path: Path to the PDF that you want to convert
:type pdf_path: Union[str, PurePath]
:param dpi: Image quality in DPI (default 200), defaults to 200
:type dpi: int, optional
:param output_folder: Write the resulting images to a folder (instead of directly in memory), defaults to None
:type output_folder: Union[str, PurePath], optional
:param first_page: First page to process, defaults to None
:type first_page: int, optional
:param last_page: Last page to process before stopping, defaults to None
:type last_page: int, optional
:param fmt: Output image format, defaults to "ppm"
:type fmt: str, optional
:param jpegopt: jpeg options `quality`, `progressive`, and `optimize` (only for jpeg format), defaults to None
:type jpegopt: Dict, optional
:param thread_count: How many threads we are allowed to spawn for processing, defaults to 1
:type thread_count: int, optional
:param userpw: PDF's password, defaults to None
:type userpw: str, optional
:param ownerpw: PDF's owner password, defaults to None
:type ownerpw: str, optional
:param use_cropbox: Use cropbox instead of mediabox, defaults to False
:type use_cropbox: bool, optional
:param strict: When a Syntax Error is thrown, it will be raised as an Exception, defaults to False
:type strict: bool, optional
:param transparent: Output with a transparent background instead of a white one, defaults to False
:type transparent: bool, optional
:param single_file: Uses the -singlefile option from pdftoppm/pdftocairo, defaults to False
:type single_file: bool, optional
:param output_file: What is the output filename or generator, defaults to uuid_generator()
:type output_file: Any, optional
:param poppler_path: Path to look for poppler binaries, defaults to None
:type poppler_path: Union[str, PurePath], optional
:param grayscale: Output grayscale image(s), defaults to False
:type grayscale: bool, optional
:param size: Size of the resulting image(s), uses the Pillow (width, height) standard, defaults to None
:type size: Union[Tuple, int], optional
:param paths_only: Don't load image(s), return paths instead (requires output_folder), defaults to False
:type paths_only: bool, optional
:param use_pdftocairo: Use pdftocairo instead of pdftoppm, may help performance, defaults to False
:type use_pdftocairo: bool, optional
:param timeout: Raise PDFPopplerTimeoutError after the given time, defaults to None
:type timeout: int, optional
:param hide_annotations: Hide PDF annotations in the output, defaults to False
:type hide_annotations: bool, optional
:raises NotImplementedError: Raised when conflicting parameters are given (hide_annotations for pdftocairo)
:raises PDFPopplerTimeoutError: Raised after the timeout for the image processing is exceeded
:raises PDFSyntaxError: Raised if there is a syntax error in the PDF and strict=True
:return: A list of Pillow images, one for each page between first_page and last_page
:rtype: List[Image.Image]
r   r   )r.   r   
pdftocairopdftoppmr   9   NS   Fr   Tz-rz4Hide annotations flag not implemented in pdftocairo.:LD_LIBRARY_PATH Windows)envstdoutstderrstartupinfor3   zRun poppler timeout.s   Syntax Errorutf8ignore)	in_memory)+
isinstancer   as_posixpdfinfo_from_path_parse_formatTRANSPARENT_FILE_TYPES_get_poppler_versiontypesGeneratorTyper   iterr   tempfilemkdtemprangenextint_build_commandstrNotImplementedError_get_command_pathosenvironcopygetplatformsystem
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWappendr   r   communicater   killr   r   decode_load_from_output_foldershutilrmtree)/r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   
page_count
parsed_fmtfinal_extensionparse_buffer_funcuse_pdfcairo_formatuse_pdfcairopoppler_version_majorpoppler_version_minorauto_temp_dirremindercurrent_page	processes_thread_output_filethread_page_countargsr?   rB   imagesuidprocdataerroutserrss/                                                  S/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/pdf2image/pdf2image.pyconvert_from_pathr   %   s_   Z #, (H%%$$&-**%..0,))#,,."'J
 KXYKGJ!24G 	 	B	B@J*@@  4H$*<400 !&;r&A!&;r&A  k5#6#677
(A A }-KL+K8KaZ!^
I
2		a) \$,,.M M +a/
*$%L,!	|$A!%k!2 !+l :SA=N N!s3x*0014" D$ #-N  *,EFM)*lCDtK (*;;LHqL))H**//#C' 3&1BB)GG %& K I-(446##z'F'FF#&#d4[a %r "ICE ,,W,=	c #%&$SZZ%ABB(2!#+  +D11) #, MM-(M- " E		!--/
d,-CDDE& MM-( s&   .F(O N)AO 9OO  O0pdf_filec                    [         R                  " 5       u  nn [        US5       nUR                  U 5        UR	                  5         [        UR                  40 SU_SU_SU_SU_SU_SU_SU_S	U_S
U	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_6sSSS5        [        R                  " U5        [        R                  " U5        $ ! , (       d  f       O= f [        R                  " U5        [        R                  " U5        g! [        R                  " U5        [        R                  " U5        f = f)a  Function wrapping pdftoppm and pdftocairo.

:param pdf_bytes: Bytes of the PDF that you want to convert
:type pdf_bytes: bytes
:param dpi: Image quality in DPI (default 200), defaults to 200
:type dpi: int, optional
:param output_folder: Write the resulting images to a folder (instead of directly in memory), defaults to None
:type output_folder: Union[str, PurePath], optional
:param first_page: First page to process, defaults to None
:type first_page: int, optional
:param last_page: Last page to process before stopping, defaults to None
:type last_page: int, optional
:param fmt: Output image format, defaults to "ppm"
:type fmt: str, optional
:param jpegopt: jpeg options `quality`, `progressive`, and `optimize` (only for jpeg format), defaults to None
:type jpegopt: Dict, optional
:param thread_count: How many threads we are allowed to spawn for processing, defaults to 1
:type thread_count: int, optional
:param userpw: PDF's password, defaults to None
:type userpw: str, optional
:param ownerpw: PDF's owner password, defaults to None
:type ownerpw: str, optional
:param use_cropbox: Use cropbox instead of mediabox, defaults to False
:type use_cropbox: bool, optional
:param strict: When a Syntax Error is thrown, it will be raised as an Exception, defaults to False
:type strict: bool, optional
:param transparent: Output with a transparent background instead of a white one, defaults to False
:type transparent: bool, optional
:param single_file: Uses the -singlefile option from pdftoppm/pdftocairo, defaults to False
:type single_file: bool, optional
:param output_file: What is the output filename or generator, defaults to uuid_generator()
:type output_file: Any, optional
:param poppler_path: Path to look for poppler binaries, defaults to None
:type poppler_path: Union[str, PurePath], optional
:param grayscale: Output grayscale image(s), defaults to False
:type grayscale: bool, optional
:param size: Size of the resulting image(s), uses the Pillow (width, height) standard, defaults to None
:type size: Union[Tuple, int], optional
:param paths_only: Don't load image(s), return paths instead (requires output_folder), defaults to False
:type paths_only: bool, optional
:param use_pdftocairo: Use pdftocairo instead of pdftoppm, may help performance, defaults to False
:type use_pdftocairo: bool, optional
:param timeout: Raise PDFPopplerTimeoutError after the given time, defaults to None
:type timeout: int, optional
:param hide_annotations: Hide PDF annotations in the output, defaults to False
:type hide_annotations: bool, optional
:raises NotImplementedError: Raised when conflicting parameters are given (hide_annotations for pdftocairo)
:raises PDFPopplerTimeoutError: Raised after the timeout for the image processing is exceeded
:raises PDFSyntaxError: Raised if there is a syntax error in the PDF and strict=True
:return: A list of Pillow images, one for each page between first_page and last_page
:rtype: List[Image.Image]
wbr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   N)
rP   mkstempopenwriteflushr   namerY   closeremove)r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   fhtemp_filenamefs                            r   convert_from_bytesr     s~   Z !((*B!-&!GGHGGI$ , &	
 $    *    (  ( ( (  *!" $#$ %& &'(  .)*  +, "2- '&8 	
		- ; '&&8 	
		-  	
		- s#   D A4C	D 
CD .D=ry   c           	         U	(       a  U R                  S5        U(       a  U R                  S5        U
(       a  U[        ;   a  U R                  S5        Ub  U R                  S[        U5      /5        Ub  U R                  S[        U5      /5        US;  a  U R                  SU-   5        US;   a#  U(       a  U R                  S	[	        U5      /5        U(       a  U R                  S
5        Ub.  U R                  [
        R                  R                  X5      5        Ub  U R                  SU/5        Ub  U R                  SU/5        U(       a  U R                  S5        Uc   U $ [        U[        5      (       a  [        U5      S:X  a  US   b)  U R                  S[        [        US   5      5      /5        OU R                  S[        S5      /5        US   b*  U R                  S[        [        US   5      5      /5        U $ U R                  S[        S5      /5         U $ [        U[        5      (       a9  [        U5      S:X  a*  U R                  S[        [        US   5      5      /5        U $ [        U[        5      (       d  [        U[        5      (       a'  U R                  S[        [        U5      5      /5        U $ [        SU S35      e)Nz-cropboxz-hide-annotationsz-transp-f-l)pgmr   -jpegjpgz-jpegoptz-singlefile-upw-opwz-gray   r   z-scale-to-xr   z-scale-to-yz	-scale-tozSize z is not a tuple or an integer)rc   rK   extendrV   _parse_jpegoptrY   pathjoinrG   tuplelenrT   float
ValueError)ry   r!   r"   r#   r$   r%   r-   r'   r(   r)   r+   r,   r/   r0   r4   s                  r   rU   rU     sU   " J'(s44IT3z?+,T3y>*+
. C#I
o'Z!89:M" BGGLL<=VV$%VW%&G|" K! 
D%	 	 SY!^7KKCQL(9:;KKB017KKCQL(9:; K KKB01 K 
D%	 	 SY!^[#c$q'l"345 K 
D#		*T5"9"9[#c$i.12 K 5&CDEE    c                     U R                  5       n U S   S:X  a  U SS  n U S;   a
  SS[        S4$ U S:X  a
  SS[        S4$ U S	;   a  g
U S:X  a  U(       a
  SS[        S4$ SS[        S4$ )Nr   .r   r   r   r   Fr   )tifr   )r   r   NTr   r   )lowerr   r   r   r   )r$   r/   s     r   rJ   rJ     s    
))+C
1v}!"g
ou2E99
e|e0%77
o(
e|	e0%77%,e33r   c                     / nU R                  5        H3  u  p#USL a  SnUSL a  SnUR                  SR                  X#5      5        M5     SR                  U5      $ )NTyFnz{}={},)itemsrc   formatr   )r%   partskvs       r   r   r     sV    E9A:AW^^A)*   88E?r   commandc                     [         R                  " 5       S:X  a  U S-   n Ub  [        R                  R	                  X5      n U $ )Nr>   z.exe)r]   r^   rY   r   r   )r   r.   s     r   rX   rX     s8    I%F"'',,|5Nr   c                 &   [        X5      S/n [        R                  R                  5       nUb  US-   UR	                  SS5      -   US'   [        X[        [        S9n UR                  US9u  pV UR                  SS	5      R                  S
5      S   R                  S5      S   R                  S5      n	[        U	S   5      [        U	S   5      4$ ! [         a.    UR                  5         UR                  5       u  px[        S5      ef = f!    g= f)Nz-vr;   r<   r=   r?   r@   rA   rC   Run poppler poppler timeout.rD   rE   
r    r   r   r   )r      )rX   rY   rZ   r[   r\   r   r   rd   r   re   r   rf   splitrT   )
r   r.   r3   r?   r|   r}   r~   r   r   versions
             r   rL   rL     s    !7>G
**//
C!-!3cgg>OQS6T!T$t<DE$$W$5	**VX.44T:1=CCCHLRRSVW71:GAJ//  E		%%'
$%CDDEs   C 0A D 8D	Drawdatesc                 .    [        SU5      U /nUb  UR                  SU/5        Ub  UR                  SU/5        U(       a  UR                  S/5        U(       a  UR                  S[        U5      /5        U(       a  UR                  S[        U5      /5        [        R                  R                  5       n	Ub  US-   U	R                  S	S
5      -   U	S	'   [        X[        [        S9n
 U
R                  US9u  p0 nUR                  SS5      R                  S5       Hk  nUR                  S5      nUS   SR                  USS 5      nnUS
:w  d  M5  U[         ;   a  [#        UR%                  5       5      OUR%                  5       UU'   Mm     SU;  a  [&        eU$ ! [         a.    U
R                  5         U
R                  5       u  p[        S5      ef = f! [(         a    [+        S5      e[&         a    [-        SWR                  SS5       35      ef = f)a  Function wrapping poppler's pdfinfo utility and returns the result as a dictionary.

:param pdf_path: Path to the PDF that you want to convert
:type pdf_path: str
:param userpw: PDF's password, defaults to None
:type userpw: str, optional
:param ownerpw: PDF's owner password, defaults to None
:type ownerpw: str, optional
:param poppler_path: Path to look for poppler binaries, defaults to None
:type poppler_path: Union[str, PurePath], optional
:param rawdates: Return the undecoded data strings, defaults to False
:type rawdates: bool, optional
:param timeout: Raise PDFPopplerTimeoutError after the given time, defaults to None
:type timeout: int, optional
:param first_page: First page to process, defaults to None
:type first_page: int, optional
:param last_page: Last page to process before stopping, defaults to None
:type last_page: int, optional
:raises PDFPopplerTimeoutError: Raised after the timeout for the image processing is exceeded
:raises PDFInfoNotInstalledError: Raised if pdfinfo is not installed
:raises PDFPageCountError: Raised if the output could not be parsed
:return: Dictionary containing various information on the PDF
:rtype: Dict
pdfinfoNr   r   z	-rawdatesr   r   r;   r<   r=   r   rC   r   rD   rE   r   r   r   r   z;Unable to get page count. Is poppler installed and in PATH?zUnable to get page count.
)rX   r   rV   rY   rZ   r[   r\   r   r   rd   r   re   r   rf   r   r   PDFINFO_CONVERT_TO_INTrT   stripr   OSErrorr   r   )r   r'   r(   r.   r   r3   r"   r#   r   r?   r|   outr~   r   r   dfieldsfkeyvalues                       r   rI   rI     s
   D6
$Y=xHNNFF+,NNFG,-NNK=)NND#j/23NND#i.12 jjoo#%1C%7#''BSUW:X%XC!"Wd4@	I'''8HC ZZ177=ES!BAAB 0Cby 44 & #	 > !'  	IIIK))+JD()GHH	I*  
&I
 	
  
)#**VX*F)GH
 	

s,   C(G +F <AG AG 8GG =H	pdf_bytesc                    [         R                  " 5       u  p [        U	S5       n
U
R                  U 5        U
R	                  5         SSS5        [        U	UUUUUUUS9[        R                  " U5        [        R                  " U	5        $ ! , (       d  f       NJ= f! [        R                  " U5        [        R                  " U	5        f = f)a  Function wrapping poppler's pdfinfo utility and returns the result as a dictionary.

:param pdf_bytes: Bytes of the PDF that you want to convert
:type pdf_bytes: bytes
:param userpw: PDF's password, defaults to None
:type userpw: str, optional
:param ownerpw: PDF's owner password, defaults to None
:type ownerpw: str, optional
:param poppler_path: Path to look for poppler binaries, defaults to None
:type poppler_path: Union[str, PurePath], optional
:param rawdates: Return the undecoded data strings, defaults to False
:type rawdates: bool, optional
:param timeout: Raise PDFPopplerTimeoutError after the given time, defaults to None
:type timeout: int, optional
:param first_page: First page to process, defaults to None
:type first_page: int, optional
:param last_page: Last page to process before stopping, defaults to None
:type last_page: int, optional
:return: Dictionary containing various information on the PDF
:rtype: Dict
r   N)r'   r(   r.   r   r3   r"   r#   )	rP   r   r   r   r   rI   rY   r   r   )r   r'   r(   r.   r   r3   r"   r#   r   r   r   s              r   pdfinfo_from_bytesr   h  s    > !((*B!-&!GGIGGI ' !%!	
 	
		-  '& 	
		- s"   B "BB 
BB .C
extrF   c           	         / n[        [        R                  " U 5      5       H  nUR                  U5      (       d  M  UR	                  S5      S   U:X  d  M5  U(       a0  UR                  [        R                  R                  X5      5        Ml  UR                  [        R                  " [        R                  R                  X5      5      5        U(       d  M  US   R                  5         M     U$ )Nr   r   )sortedrY   listdir
startswithr   rc   r   r   r   r   load)r!   r-   r   r1   rF   rz   r   s          r   rg   rg     s     FBJJ}-.<<$$b)9S)@bggll=<=ejjm)GHI92JOO% / Mr   )F)N)NN)NNNFNNN)3__doc__rY   r]   rP   rM   rh   r_   r   r   r   typingr   r   r   r	   r
   r   pathlibr   PILr   pdf2image.generatorsr   r   r   pdf2image.parsersr   r   r   r   pdf2image.exceptionsr   r   r   r   rK   r   rV   rT   boolr   bytesr   rU   rJ   r   rX   rL   rI   r   rg    r   r   <module>r      s  
 
      2 2 : :   W W     ! 
 *.%')-" "-mCM"m	m h'm 	m
 m 
m m m m m m m m m m  X&!m" #m$ s

%m& 'm( )m* +m, -m. 
%++/md *.(6(8)-" "-l!l!	l! h'l! 	l!
 l! 
l! l! l! l! l! l! l! l! l! sH}%l!  X&!l!" #l!$ s

%l!& 'l!( )l!* +l!, -l!. 
%++/l!^G
GG G 	G
 
G G G G G G G G G U38_$
%G G  
#Y!GT4s 4t 4c3RV>V8W 4 D S s #   <@ #58
38_8 X
X
X
 X
 	X

 X
 X
 X
 X
 
X
z 0!0!0! 0! 	0!
 0! 0! 0! 0! 
0!p  
 	
  
%++r   