
    ;3hE                        d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
mZmZ ddlmZ dedee   fd	Zd
ee   de j$                  fdZdedeeee	f      ddfdZej*                  dd fd
ee   ddfdZedk(  r e        yy)    N)defaultdictdeque)chain)AnyDefaultDictDictList   )PDFp_strreturnc                     d| v r:t        t        | j                  d            \  }}t        t	        ||dz               S t        |       gS )N-r
   )mapintsplitlistrange)r   startends      N/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/pdfplumber/cli.pyparse_page_specr      sD    
e|ekk#./
sE%q)**E
|    args_rawc                    t        j                  d      }|j                  ddt        j                  d      t        j
                  j                         |j                         }|j                  ddd	       |j                  d
dd	       |j                  dg dd       |j                  dd       |j                  ddd       |j                  ddd       |j                  dt        j                         |j                  dt               |j                  ddt               |j                  dt        d       |j                  |       }|j                   t        t        |j                         |_        |S ) N
pdfplumberinfile?rb)nargstypedefaultz--structurezoWrite the structure tree as JSON.  All other arguments except --pages, --laparams, and --indent will be ignored
store_true)helpactionz--structure-textzWrite the structure tree as JSON including text contents.  All other arguments except --pages, --laparams, and --indent will be ignoredz--format)csvjsontextr&   )choicesr"   z--types+)r    z--include-attrsz1Include *only* these object attributes in output.)r    r$   z--exclude-attrsz,Exclude these object attributes from output.z
--laparams)r!   z--precisionz--pages)r    r!   z--indentz&Indent level for JSON pretty-printing.)r!   r$   )argparseArgumentParseradd_argumentFileTypesysstdinbufferadd_mutually_exclusive_groupr'   loadsr   r   
parse_argspagesr   r   )r   parsergroupargss       r   r4   r4      s   $$\2F
("3"3D"9399CSCS   //1E	W	   
W	   
,CUS
	-
@   ;   4::6
C0
	?C
#K   X&Dzz%,-
Kr   pdfdatac                    t        d       }| j                  D ]F  }||j                     }|j                  D ]&  }|j	                  d      }|||xx   |d   z  cc<   ( H t        |      }|rb|j                         }d|v r|j                  |d          |j	                  d      }	|	>||	   }d|v r|d   D cg c]  }||   	 c}|d<   |ray y c c}w )Nc                       t        t              S )N)r   str r   r   <lambda>z#add_text_to_mcids.<locals>.<lambda>I   s    {3?O r   mcidr(   childrenpage_numbermcids)r   r5   rB   charsgetr   popleftextend)
r9   r:   page_contentspagetext_contentscr@   delpagenos
             r   add_text_to_mcidsrO   H   s    +67O+PM		 -%d&6&67 	-A55=D|$1V9,		-- 	dA
YY[HHR
^$&>%f-b=:<W+F$--FBvJ  Gs   ;Cc           	         t        |       }t        j                  |j                  |j                  |j
                        5 }|j                  r6t        t        j                  |j                  |j                               n?|j                  rD|j                  }t        ||       t        t        j                  ||j                  d             n|j                  dk(  rM|j                  t         j"                  |j$                  |j&                  |j(                  |j*                         n|j                  dk(  r-|j                  D ]  }t        |j-                  d	              nW|j/                  t         j"                  |j$                  |j&                  |j(                  |j*                  |j                  
       d d d        y # 1 sw Y   y xY w)N)r5   laparams)indentF)rR   ensure_asciir&   )	precisioninclude_attrsexclude_attrsr(   T)layout)rT   rU   rV   rR   )r4   r   openr   r5   rQ   	structureprintr'   dumpsstructure_treerR   structure_textrO   formatto_csvr/   stdouttypesrT   rU   rV   extract_textto_json)r   r8   r9   treerI   s        r   mainre   ^   sV   hD	$++TZZ$--	H C>>$**S//DE  %%Dc4($**T$++EJK[[E!JJ



.."00"00   [[F"		 6d''t'456 KK



.."00"00{{  '  s   FGG__main__)r+   r'   r/   collectionsr   r   	itertoolsr   typingr   r   r   r	   r9   r   r=   r   r   	Namespacer4   rO   argvre   __name__r>   r   r   <module>rm      s      
 *  / / 3 49 1c 1x'9'9 1hG3 Gd4S>&: Gt G,  #xx| 49  @ zF r   