o
    f	                     @   sP   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 dd Zdd ZdS )    N)Path)	add_input	get_inputc                 C   sd   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 d S )NT)pagesz--output-dirz-oz-Output directory to take the extracted images)requiredtypehelpz--max-depth   zBMaximum recursion depth to consider when looking for page objects.)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--renderzxWhether to get rendered bitmaps, taking masks and transform matrices into account. (Fallback if doing smart extraction.))r   add_argumentr   int)parser r   V/home/ubuntu/webapp/venv/lib/python3.10/site-packages/pypdfium2/_cli/extract_images.pyattach   s6   
r   c              
   C   s0  | j  s
t| j | jr| jsd| _t| }ttt| j	d }| j	D ]p}|| }|j
tjf| jd}t|}ttt|}t|D ]O\}}d| jj||d ||d f }	| j |	 }
z$| jrv|j| jd }||
d| j  n
|j|
| j| jd W n tjy   t  Y nw |  qEq%d S )Npng   )filter	max_depthz%s_%0*d_%0*d)render.)	fb_format	fb_render)
output_diris_dirNotADirectoryError
use_bitmapformatr   lenstrmaxr   get_objectspdfium_cFPDF_PAGEOBJ_IMAGEr   list	enumerateinputstem
get_bitmapr   to_pilsavewith_suffixextractpdfiumPdfiumError	traceback	print_excclose)argspdf	n_pdigitsipageimages	n_idigitsjimager)   prefix	pil_imager   r   r   main,   s:   




r?   )r1   pathlibr   pypdfium2.rawrawr$   pypdfium2._helpers_helpersr/   pypdfium2._cli._parsersr   r   r   r?   r   r   r   r   <module>   s   