
    Mg
                     Z    S SK r S SKJr  S SKJr  S SKJr  \" S5       " S S5      5       rg)    N)plugin)Fore)convert_from_pathzpdf to imagesc                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)
PdfToImage   zZ
A tool for converting and storing all the
pages of a pdf in form of a images in a folder
c                     S U l         g Npath)selfs    >/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/pdftoimg.py__init__PdfToImage.__init__   s	    	    c                 &    U R                  U5        g r
   )
pdf_to_img)r   jarvisss      r   __call__PdfToImage.__call__   s    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      (       a  O"UR                  S[        R                  5        Mn  U R                  X15      nOUR                  5         M  UR                  U R                  5      nU R                  XEU5        GM.  )N z-This tool will help you convert pdf to imageszYour choice: qquit2zSee you next time :D1z Enter the full path of the pdf: z.pdfz=Opps! Looks like you entered an invalid path. Kindly Re-enter)sayavailable_optionsinputlowerr   CYANosr   existsendswithREDconvert_to_imagesincorrect_optionget_saving_directorysave_images)r   r   
user_inputpdf_pathpagesdestinations         r   r   PdfToImage.pdf_to_img   s!   

2

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

1499= s"%||,NOHww~~h//X5F5Fv5N5N

[]a]e]eg  ..x@ '') 55dii@KU87 r   c                 (    Xl         [        U5      nU$ )zK
Convert all the pages in the pdf to individual
pages option and return it
)r   r   )r   r,   r   r-   s       r   r'   PdfToImage.convert_to_images4   s    
 	!(+r   c                 j    UR                  S5        UR                  S5        UR                  S5        g)zD
Message displayed to prompt the user about converting
pdf to image
z$Select one of the following options:z1: Convert pdf to imagesz2: QuitN)r   )r   r   s     r   r   PdfToImage.available_options=   s*    
 	

9:

-.

9r   c                     SnU H)  nUR                  S[        U5      -   S-   S5        US-  nM+     UR                  S[        R                  5        g)z=
Save the thus generated images to the destination
specified
   page_z.jpgJPEGz"Your images are saved successfullyN)savestrr   r   GREEN)r   r-   r.   r   
page_countpages         r   r*   PdfToImage.save_imagesF   sM    
 
DIIgJ/&8&A!OJ  	

7Dr   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r'   r   r*   __static_attributes__ r   r   r   r      s'    
 9@
Er   r   )r#   r   coloramar   	pdf2imager   r   rD   r   r   <module>rG      s5    	   ' HE HE HEr   