
    iJ                     6    d Z ddlmZ ddlmZ dedee   fdZy)z`
PDF text extraction utilities.

Provides text extraction from PDF files using pypdf or PyPDF2.
    )Optional)verbose_loggerfile_contentreturnc                    	 ddl m} 	 ddlm}  ||       } ||      }g }|j                  D ]&  }|j                         }|s|j                  |       ( |r5dj                  |      }t        j                  dt        |       d       |S 	 	 ddlm}	  ||       } |	|      }g }|j                  D ]&  }|j                         }|s|j                  |       ( |r5dj                  |      }t        j                  dt        |       d       |S 	 y# t        $ r t        j                  d       Y w xY w# t        $ r t        j                  d	       Y yw xY w# t        $ r"}
t        j                  d
|
        Y d}
~
yd}
~
ww xY w)z
    Extract text from PDF using pypdf if available.

    Args:
        file_content: Raw PDF bytes

    Returns:
        Extracted text or None if extraction fails
    r   )BytesIO)	PdfReaderz

z
Extracted z  characters from PDF using pypdfz"pypdf not available, trying PyPDF2z! characters from PDF using PyPDF2zIPyPDF2 not available, PDF extraction requires OCR or pypdf/PyPDF2 libraryzPDF text extraction failed: N)ior   pypdfr	   pagesextract_textappendjoinr   debuglenImportErrorPyPDF2	Exception)r   r   PypdfReaderpdf_filereader
text_partspagetextextracted_textPyPDF2Readeres              ~/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/rag/ingestion/file_parsers/pdf_parser.pyextract_text_from_pdfr      s   4A	G6|,H *FJ((*%%d+ %
 !'Z!8$$ ^!4 55UV &% 	8|,H!(+FJ((*%%d+ %
 !'Z!8$$ ^!4 55VW &%  ?  	G  !EF	G.  	  [ 	
  A;A3?@@Asf   E 9D A	D E 9D9 	A	D9 D63E 5D66E 9EE EE 	F&FFN)__doc__typingr   litellm._loggingr   bytesstrr        r   <module>r'      s,     +@ @(3- @r&   