Ë
    ðì�i•  ã                   ón   — d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZmZ d
„ Zy)zY
PassportEye::Util: PDF processing utilities.

Author: Konstantin Tretyakov
License: MIT
é    N)Ú	PDFParser)ÚPDFDocument)ÚPDFPage)ÚPDFResourceManager)ÚPDFPageInterpreter)ÚPDFPageAggregator)ÚLTFigureÚLTImagec                 óø  — t        | «      }t        |«      }t        «       }t        |«      }t	        ||«      }t        j                  |«      }|D ]ˆ  }|j                  |«       |j                  }|D ]d  }	t        |	t        «      sŒ|	D ]L  }
t        |
t        «      sŒd}	 |
j                  j                  «       }|€Œ4|j                  d«      sŒF|c c c S  Œf ŒŠ y#  |
j                  j                  «       }Y ŒAxY w)aÈ  
    Reads a given PDF file and scans for the first valid embedded JPEG image.
    Returns either None (if none found) or a string of data for the image.
    There is no 100% guarantee for this code, yet it seems to work fine with most
    scanner-produced images around.
    More testing might be needed though.

    Note that in principle there is no serious problem extracting PNGs or other image types from PDFs,
    however at the moment I do not have enough test data to try this, and the one I have seems to be unsuitable
    for PDFMiner.

    :param fstream: Readable binary stream of the PDF
    :return: binary stream, containing the whole contents of the JPEG image or None if extraction failed.
    Ns   ÿØÿà)r   r   r   r   r   r   Úcreate_pagesÚprocess_pageÚresultÚ
isinstancer	   r
   ÚstreamÚget_dataÚget_rawdataÚ
startswith)ÚfstreamÚparserÚdocumentÚrsrcmgrÚdeviceÚinterpreterÚpagesÚpageÚlayoutÚelÚimÚstÚimdatas                úy/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/passporteye/util/pdf.pyÚextract_first_jpeg_in_pdfr"      só   € ô �wÓ€FÜ˜6Ó"€HÜ Ó"€GÜ˜wÓ'€FÜ$ W¨fÓ5€KÜ× Ñ  Ó*€EØò *ˆØ× Ñ  Ô&Ø—‘ˆØò 	*ˆBÜ˜"œhÕ'Øò 
*�BÜ! "¤gÕ.à!˜ð=Ø%'§Y¡Y×%7Ñ%7Ó%9˜Fð "Ñ-°&×2CÑ2CÐDWÕ2XØ#)žMñ
*ñ	*ð*ð" øð=à%'§Y¡Y×%:Ñ%:Ó%<šFús   ÂCÃC9	)Ú__doc__ÚsysÚpdfminer.pdfparserr   Úpdfminer.pdfdocumentr   Úpdfminer.pdfpager   Úpdfminer.pdfinterpr   r   Úpdfminer.converterr   Úpdfminer.layoutr	   r
   r"   © ó    r!   ú<module>r-      s)   ðñó å (Ý ,Ý $Ý 1Ý 1Ý 0ß -ó&r,   