
    #j`              #          d 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 ddlmZmZmZmZmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZmZ ddlm Z  ddl!m"Z"m#Z#m$Z$ 	 	 	 	 	 	 	 	 	 	 	 	 	 d+de
de"de%de%dedz  de&dee&         dz  de%de'de&de%de%dz  d e(d!e(d"e(d#e	d$df"d%Z)	 	 	 	 	 	 d,d'e#de%dee&         dz  de&d(e(de%dedz  d$e%fd)Z*	 	 	 	 	 d-d'e#de%dee&         dz  de&d(e(dedz  d$ee         fd*Z+dS ).zIFunctions that can be used for the most common use-cases for pdfminer.six    N)	ContainerIterator)StringIO)AnyBinaryIOcast)HOCRConverterHTMLConverterPDFPageAggregatorTextConverterXMLConverter)ImageWriter)LAParamsLTPage)	PDFDeviceTagExtractor)PDFValueError)PDFPageInterpreterPDFResourceManager)PDFPage)AnyIO
FileOrNameopen_filenametextutf-8       ?normalFinfoutfpoutput_typecodeclaparamsmaxpagespage_numberspasswordscalerotation
layoutmode
output_dirstrip_controldebugdisable_cachingkwargsreturnc           	      :   |r0t          j                                        t           j                   d}|rt	          |          }t          |           }d}|dk    r!|t          j        k    rt          j        j        }|dk    rt          |||||          }n|dk    rt          ||||||          }nx|dk    rt          |||||
||          }n[|d	k    rt          |||||
          }n@|dk    r&t          |t          t          |          |          }nd| }t!          |          |J t#          ||          }t%          j        | ||||           D ])}|j        |	z   dz  |_        |                    |           *|                                 dS )ak  Parses text from inf-file and writes to outfp file-like object.

    Takes loads of optional arguments but the defaults are somewhat sane.
    Beware laparams: Including an empty LAParams is not the same as passing
    None!

    :param inf: a file-like object to read PDF structure from, such as a
        file handler (using the builtin `open()` function) or a `BytesIO`.
    :param outfp: a file-like object to write the text to.
    :param output_type: May be 'text', 'xml', 'html', 'hocr', 'tag'.
        Only 'text' works properly.
    :param codec: Text decoding codec
    :param laparams: An LAParams object from pdfminer.layout. Default is None
        but may not layout correctly.
    :param maxpages: How many pages to stop parsing after
    :param page_numbers: zero-indexed page numbers to operate on.
    :param password: For encrypted PDFs, the password to decrypt.
    :param scale: Scale factor
    :param rotation: Rotation factor
    :param layoutmode: Default is 'normal', see
        pdfminer.converter.HTMLConverter
    :param output_dir: If given, creates an ImageWriter for extracted images.
    :param strip_control: Does what it says on the tin
    :param debug: Output more logging data
    :param disable_caching: Does what it says on the tin
    :param other:
    :return: nothing, acting as it does on two streams. Use StringIO to get
        strings.
    Ncachingr   )r"   r#   imagewriterxml)r"   r#   r3   stripcontrolhtml)r"   r'   r)   r#   r3   hocr)r"   r#   r5   tag)r"   z1Output type can be text, html, xml or tag but is r$   r&   r2   ih  )logging	getLoggersetLevelDEBUGr   r   sysstdoutbufferr   r   r
   r	   r   r   r   r   r   r   	get_pagesrotateprocess_pageclose)r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r3   rsrcmgrdevicemsginterpreterpages                         [/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pdfminer/high_level.pyextract_text_to_fprK      s$   ^  4$$W]333K .!*-- _)<===G#Ff#*!4!4
!f#
 
 
 
		#&
 
 
 
		!#
 
 
 
		&
 
 
 
		gtHe'<'<EJJJ P+OOC   $Wf55K!##   ' ' {X-4  &&&&
LLNNNNN    Tpdf_filer2   c           	         |t                      }t          | d          5 }t                      5 }t          t          |          }t          |          }	t          |	|||          }
t          |	|
          }t          j	        |||||          D ]}|
                    |           |                                cddd           cddd           S # 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )aw  Parse and return the text contained in a PDF file.

    :param pdf_file: Either a file path or a file-like object for the PDF file
        to be worked on.
    :param password: For encrypted PDFs, the password to decrypt.
    :param page_numbers: List of zero-indexed page numbers to extract.
    :param maxpages: The maximum number of pages to parse
    :param caching: If resources should be cached
    :param codec: Text decoding codec
    :param laparams: An LAParams object from pdfminer.layout. If None, uses
        some default settings that often work well.
    :return: a string containing all of the text extracted.
    Nrbr1   )r"   r#   r9   )r   r   r   r   r   r   r   r   r   rA   rC   getvalue)rM   r&   r%   r$   r2   r"   r#   fpoutput_stringrE   rF   rH   rI   s                rJ   extract_textrS      s   , ::	x	&	& ("hjj (M(B$W555wUXVVV(&99%
 
 
 	+ 	+D $$T****%%''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s5   C.BC=C.C	C.C	C..C25C2c              #     K   |t                      }t          | d          5 }t          t          |          }t	          |          }t          ||          }t          ||          }	t          j        |||||          D ]/}
|		                    |
           |
                                }|V  0	 ddd           dS # 1 swxY w Y   dS )a  Extract and yield LTPage objects

    :param pdf_file: Either a file path or a file-like object for the PDF file
        to be worked on.
    :param password: For encrypted PDFs, the password to decrypt.
    :param page_numbers: List of zero-indexed page numbers to extract.
    :param maxpages: The maximum number of pages to parse
    :param caching: If resources should be cached
    :param laparams: An LAParams object from pdfminer.layout. If None, uses
        some default settings that often work well.
    :return: LTPage objects
    NrO   r1   )r#   r9   )r   r   r   r   r   r   r   r   rA   rC   
get_result)rM   r&   r%   r$   r2   r#   rQ   resource_managerrF   rH   rI   layouts               rJ   extract_pagesrX      s2     ( ::	x	&	& "(B-g>>>"#3hGGG()96BB%
 
 
 		 		D $$T***&&((FLLLL		                 s   BCCC)r   r   Nr   Nr   r   r   r   NFFF)r   Nr   Tr   N)r   Nr   TN),__doc__r:   r>   collections.abcr   r   ior   typingr   r   r   pdfminer.converterr	   r
   r   r   r   pdfminer.imager   pdfminer.layoutr   r   pdfminer.pdfdevicer   r   pdfminer.pdfexceptionsr   pdfminer.pdfinterpr   r   pdfminer.pdfpager   pdfminer.utilsr   r   r   strintfloatboolrK   rS   rX    rL   rJ   <module>rj      sh   O O  



 / / / / / / / /       & & & & & & & & & &              ' & & & & & , , , , , , , , 6 6 6 6 6 6 6 6 0 0 0 0 0 0 E E E E E E E E $ $ $ $ $ $ ; ; ; ; ; ; ; ; ; ;  $*.!!w w	ww w 	w
 ow w C.4'w w w w w d
w w w w  !w" 
#w w w wx *. $(( (((((( C.4'(( 	((
 (( (( o(( 	(( (( (( ((Z *. $% %%% C.4'% 	%
 % o% f% % % % % %rL   