o
    f                     @   sP   d dl mZ d dlmZ zd dlZW n ey   dZY nw dd Zdd Z	dS )    )PathNc                 C   s:   | j dddtd | j dddtdd	 | j d
ddd d S )Nimages+zInput images)nargshelptypez--outputz-oTzTarget path for the new PDF)requiredr   r   z--inline
store_truez9If JPEG, whether to use PDFium's inline loading function.)actionr   )add_argumentr   )parser r   P/home/ubuntu/webapp/venv/lib/python3.10/site-packages/pypdfium2/_cli/imgtopdf.pyattach   s"   
r   c           	      C   s   t j }| jD ]Y}t j|}|j dv r |j|| jd nt	j
|}t j|}|  || |  | \}}|t  || |||}|| |  |  |  q|| j |  d S )N)z.jpgz.jpeg)inline)pdfiumPdfDocumentnewr   PdfImagesuffixlower	load_jpegr   PILImageopen	PdfBitmapfrom_pilclose
set_bitmapget_size
set_matrix	PdfMatrixscalenew_page
insert_objgen_contentsaveoutput)	argspdffp	image_obj	pil_imagebitmapwhpager   r   r   main#   s&   




r1   )
pathlibr   pypdfium2._helpers_helpersr   	PIL.Imager   ImportErrorr   r1   r   r   r   r   <module>   s   