
    Mg                     b    S SK r S SKJr  S SKrS SKJr  S SKJr  \" S5       " S S5      5       rg)    N)Image)plugin)Forezimage to pdfc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)
ImageToPDF   z'
A tool to converrt images to pdf file
c                      S U l         S U l        g N)pathimage)selfs    >/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/imgtopdf.py__init__ImageToPDF.__init__   s    	
    c                 &    U R                  U5        g r
   )imgtopdf)r   jarvisss      r   __call__ImageToPDF.__call__   s    fr   c                    UR                  S5        UR                  S5         U R                  U5        UR                  S5      nUR                  5       nUS:X  d  US:X  d  US:X  a!  UR                  S[        R
                  5        g US:X  a   UR                  S	5      n[        R                  R                  U5      (       a-  UR                  S
5      (       d  UR                  S5      (       a  O"UR                  S[        R                  5        M  U R                  X5      nOUS:X  ak   UR                  S5      n[        R                  R                  U5      (       a  O"UR                  S[        R                  5        MX  U R                  X5      nOUR                  5         GM  UR                  U R                  5      nUR                  S5      nUS-   U-   S-   n[        SU-   5        U R!                  XU5        GM  )N z,This tool will help you convert image to pdfzYour choice: qquit3zSee you next time :D1z"Enter the full path of the image: .jpg.pngz=Opps! Looks like you entered an invalid path. Kindly Re-enter2z#Enter the full path of the folder: z&What would you like to name your pdf? /z.pdfzFinal Destination )sayavailable_optionsinputlowerr   CYANosr   existsendswithREDsingle_image_to_pdffolder_to_pdfincorrect_optionget_saving_directoryprintsave_pdf)	r   r   
user_input
image_path	pdf_bytesfolder_pathdestination	file_namepdf_destinations	            r   r   ImageToPDF.imgtopdf   s   

2

AB""6*o6J#))+JS J&$8J#<M

1499= s"!'<">Jww~~j11z7J7J67R7RV`ViVijpVqVq

[]a]e]eg  !44VH	 s""(,,=#?Kww~~k22

[]a]e]eg  !..vC	 '') 55dii@K%MNI)C/);fDO&89MM&_=Y r   c                     UR                  S5        UR                  S5        UR                  S5        UR                  S5        g)zE
Message displayed to prompt the user about converting
images to pdf
z$Select one of the following options:z1: Convert a single imagez#2: Convert all images of the folderz3: QuitN)r"   )r   r   s     r   r#   ImageToPDF.available_optionsG   s7    
 	

9:

./

89

9r   c                     X l         [        R                  " U5      U l        [        R
                  " U R                  R                  5      nU R                  R                  5         U$ )zR
This function is used to convert a single image
with a given path to a pdf file.
)r   r   openr   img2pdfconvertfilenameclose)r   r   r2   r3   s       r   r+   ImageToPDF.single_image_to_pdfQ   sG    
 	ZZ
+
OODJJ$7$78	

r   c                 `   X l         / n[        R                  " U R                   5        [        R                  " [        R                  " 5       5       HB  nUR                  S5      (       d  UR                  S5      (       d  M1  UR                  U5        MD     [        R                  " U5      nU$ )z]
This function is used to convert all the images
in a given folder path to a single PDF file
r   r   )	r   r'   chdirlistdirgetcwdr)   appendr=   r>   )r   r   r4   source_imagesr   r3   s         r   r,   ImageToPDF.folder_to_pdf\   sx    
  	
ZZ		,E~~f%%)?)?$$U+ - OOM2	r   c                     [        US5      nUR                  U5        UR                  5         UR                  S[        R
                  5        g)zX
Save the pdf to the thus supplied location
or prompt the user to choose a new location
wbz Your pdf is created successfullyN)r<   writer@   r"   r   GREEN)r   r   r3   r5   pdf_files        r   r0   ImageToPDF.save_pdfj   s9    
 T*y!

5tzzBr   )r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r#   r+   r,   r0   __static_attributes__ r   r   r   r      s,    
/>b	Cr   r   )r=   PILr   r'   r   coloramar   r   rU   r   r   <module>rX      s8      	   iC iC iCr   