
    NgI&              #          d Z ddlZddlZddlZddlmZmZmZmZm	Z	 ddl
ZddlmZ ddlmZ  ej                     dZdede	e         fd	Zg d
dddddddddddddfdee         dede	e         dedededede	ee                  dedededede	e         deded edef"d!Zdej        fd"Zd#e	ee                  dej        fd$Zd'd#e	ee                  defd%Zed&k    r ej         e                       dS dS )(zkA command line tool for extracting text and images from PDF and
output it to plain text, html, xml or tags.    N)Any	ContainerIterableListOptional)LAParams)AnyIO))z.htmhtml)z.htmlr
   )z.xmlxml)z.tagtagxreturnc                     |                                                                  dk    rd S 	 t          |           S # t          $ r( t	          j        d                    |                     w xY w)Ndisabledzinvalid float value: {})lowerstripfloat
ValueErrorargparseArgumentTypeErrorformat)r   s    P/var/www/html/ai-engine/env/lib/python3.11/site-packages/../../../bin/pdf2txt.pyfloat_or_disabledr      st    wwyyJ&&tNQxx N N N()B)I)I!)L)LMMMNs	   = 2A/-textutf-8F       ?normalfilesoutfilelaparamsoutput_typecodecstrip_controlmaxpagespage_numberspasswordscalerotation
layoutmode
output_dirdebugdisable_cachingkwargsc                    | st          d          |dk    r*|dk    r$t          D ]\  }}|                    |          r|}|dk    r t          j        }t          j        j        d}nt          |d          }| D ]M}t          |d          5 }t          j        j	        |fi t                       d d d            n# 1 swxY w Y   N|S )Nz Must provide files to work upon!r   r   r   wbrb)r   OUTPUT_TYPESendswithsysstdoutencodingopenpdfminer
high_levelextract_text_to_fplocals)r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   overridealttypeoutfpfnamefps                        r   extract_textrB      s7   $  =;<<<fC!- 	& 	&Hg)) &%#~~z:*EWd## C C% 	C"22BBBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	CLs   $B<<C 	C 	c                     t          j        t          d          } |                     dt          d dd           |                     ddd	d
                    t          j                             |                     ddddd           |                     ddddd           |                     dd          }|                    dt          d dd           |                    ddt          d           |                    ddt          d d!"           |                    d#d$t          d%d&"           |                    d'd(d t          d)*           t                      }|                     d+d,          }|                    d-d.ddd/           |                    d0d1|j        dd2           |                    d3t          |j        d4"           |                    d5d6t          |j        d7"           |                    d8d9t          |j        d:"           |                    d;d<t          |j        d="           |                    d>d?t"          |j        d@"           |                    dAdB|j        ddC           |                     dDdE          }|                    dFdGt          dHdI"           |                    dJdKt          dLdM"           |                    dNdOt          dPdQ"           |                    dRdSd dTU           |                    dVdWdXt          dY*           |                    dZd[t          d\d]"           |                    d^d_ddd`           | S )aNT)descriptionadd_helpr    +zOne or more paths to PDF files.)typedefaultnargshelpz	--versionz-vversionzpdfminer.six v{})actionrK   z--debugz-dF
store_truezUse debug logging level.)rH   rL   rJ   z--disable-cachingz-Cz;If caching or resources, such as fonts, should be disabled.ParserzUsed during PDF parsing)rD   z--page-numbersz0A space-seperated list of page numbers to parse.z	--pagenosz-pzA comma-separated list of page numbers to parse. Included for legacy applications, use --page-numbers for more idiomatic argument entry.)rG   rJ   z
--maxpagesz-mr   z%The maximum number of pages to parse.)rG   rH   rJ   z
--passwordz-Pr   z,The password to use for decrypting PDF file.z
--rotationz-RzIThe number of degrees to rotate the PDF before other types of processing.)rH   rG   rJ   zLayout analysiszUsed during layout analysis.z--no-laparamsz-nz0If layout analysis parameters should be ignored.z--detect-verticalz-Vz<If vertical text should be considered during layout analysisz--line-overlapzIf two characters have more overlap than this they are considered to be on the same line. The overlap is specified relative to the minimum height of both characters.z--char-marginz-MzIf two characters are closer together than this margin they are considered to be part of the same line. The margin is specified relative to the width of the character.z--word-marginz-WzIf two characters on the same line are further apart than this margin then they are considered to be two separate words, and an intermediate space will be added for readability. The margin is specified relative to the width of the character.z--line-marginz-LzIf two lines are close together they are considered to be part of the same paragraph. The margin is specified relative to the height of a line.z--boxes-flowz-Fa  Specifies how much a horizontal and vertical position of a text matters when determining the order of lines. The value should be within the range of -1.0 (only horizontal position matters) to +1.0 (only vertical position matters). You can also pass `disabled` to disable advanced layout analysis, and instead return text based on the position of the bottom left corner of the text box.z--all-textsz-Az:If layout analysis should be performed on text in figures.OutputzUsed during output generation.z	--outfilez-or   zJPath to file where output is written. Or "-" (default) to write to stdout.z--output_typez-tr   z/Type of output to generate {text,html,xml,tag}.z--codecz-cr   z$Text encoding to use in output file.z--output-dirz-OzXThe output directory to put extracted images in. If not given, images are not extracted.)rH   rJ   z--layoutmodez-Yr   a2  Type of layout to use when generating html {normal,exact,loose}. If normal,each line is positioned separately in the html. If exact, each character is positioned separately in the html. If loose, same result as normal but with an additional newline after each text line. Only used when output_type is html.z--scalez-sr   zXThe amount of zoom to use when generating html file. Only used when output_type is html.z--strip-controlz-SzFRemove control statement from text. Only used when output_type is xml.)r   ArgumentParser__doc__add_argumentstrr   r9   __version__add_argument_groupintr   detect_verticalr   line_overlapchar_marginword_marginline_marginr   
boxes_flow	all_texts)parserparse_params	la_paramsla_param_groupoutput_paramss        r   create_parserrc   B   s   $4HHHF
.     "))(*>??	     '     J     ,,7 -  L ?     -	     4     ;     ,     

I..'E /  N ?      )K      &=	      %<      %?   	 	 	 %,      $"      #I      --> .  M /     >     3     $	     9     .     -     M    argsc           	         t                                          |           }|j        rd |_        n>t	          |j        |j        |j        |j        |j	        |j
        |j                  |_        |j        rd |j        D             |_        |j        r)d |j                            d          D             |_        |j        dk    r9|j        dk    r.t"          D ]&\  }}|j                            |          r||_        '|S )N)re   )rX   rY   r[   rZ   r\   rW   r]   c                     h | ]}|d z
  S     .0r   s     r   	<setcomp>zparse_args.<locals>.<setcomp>(  s    #L#L#LaAE#L#L#Lrd   c                 2    h | ]}t          |          d z
  S rh   )rV   rk   s     r   rm   zparse_args.<locals>.<setcomp>+  s"    #W#W#W1CFFQJ#W#W#Wrd   ,r   r   )rc   
parse_argsno_laparamsr"   r   rX   rY   r[   rZ   r\   rW   r]   r'   pagenossplitr#   r!   r3   r4   )re   parsed_argsr=   r>   s       r   rp   rp     s'   //,,$,77K  
#'$1#/#/#/"-'7!+ 
  
  
  M#L#L;3K#L#L#L  X#W#W8K8Q8QRU8V8V#W#W#W &(([-@C-G-G!- 	2 	2Hg"++H55 2*1'rd   c                 ~    t          |           }t          di t          |          }|                                 dS )Nr   rj   )rp   rB   varsclose)re   rt   r?   s      r   mainrx   5  s<    T""K--4,,--E	KKMMM1rd   __main__)N)rQ   r   loggingr5   typingr   r   r   r   r   pdfminer.high_levelr9   pdfminer.layoutr   pdfminer.utilsr	   basicConfigr3   rS   r   r   boolrV   rB   rP   rc   	Namespacerp   rx   __name__exitrj   rd   r   <module>r      s  / /   



 ; ; ; ; ; ; ; ; ; ; ; ; ; ;     $ $ $ $ $ $                 VN N% N N N N #'-1 $!$ $C=$$ x $ 	$
 $ $ $ 9S>*$ $ $ $ $ $ $ $  !$" #$ $ $ $NQx. Q Q Q QhXd3i( X-?    > xS	" c     zCHTTVV rd   