o
    E+ i                     @   sf   d dl 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mZmZ e eZdd Zdd ZdS )    N)Path)	add_input	get_inputBooleanOptionalActionc                 C   sv   t | dd | jdddtdd | jdtdd	d
 | jdddd | jddd | jdddd | jdtddd d S )NT)pagesz--output-dirz-oz-Output directory to take the extracted images)requiredtypehelpz--max-depth   zAMaximum recursion depth to consider when looking for pageobjects.)r   defaultr	   z--use-bitmap
store_truezREnforce the use of bitmaps rather than attempting a smart extraction of the image.)actionr	   z--formatzNImage format to use when saving bitmaps. (Fallback if doing smart extraction.))r	   z--renderznWhen --use-bitmap is given, whether to get rendered bitmaps, taking masks and transform matrices into account.z--scale-to-originalzWhen --use-bitmap --render is given, whether to scale the image so it is rendered at its native resolution, or close to that. This should improve output quality. The default is True, but you may opt out.)r   r   r	   )r   add_argumentr   intr   )parser r   i/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/pypdfium2/_cli/extract_images.pyattach   sB   
r   c              
   C   s8  | j  s
t| j | jr| jsd| _t| }ttt| j	d }| j	D ]t}|| }|j
tjf| jd}t|}ttt|}t|D ]S\}}d||d ||d f }	| j | jj d|	  }
z$| jr||j| j| jd }||
 d| j  n|j|
| jd W n tjy   t  Y nw |  qEq%d S )	NZpng   )filter	max_depthz	%0*d_%0*d_)renderscale_to_original.)Z	fb_format)
output_diris_dirNotADirectoryErrorZ
use_bitmapformatr   lenstrmaxr   Zget_objectspdfium_cZFPDF_PAGEOBJ_IMAGEr   list	enumerateinputstemZ
get_bitmapr   r   Zto_pilsaveextractpdfiumZPdfiumError	traceback	print_excclose)argsZpdfZ	n_pdigitsipageZimagesZ	n_idigitsjimagetagprefixZ	pil_imager   r   r   main7   s:   



r4   )loggingr*   pathlibr   Zpypdfium2.rawrawr"   Zpypdfium2._helpersZ_helpersr)   Zpypdfium2._cli._parsersr   r   r   	getLogger__name__loggerr   r4   r   r   r   r   <module>   s   
$