
    :QgA                         d dl Z d dlZd dlZd dlmZ d dlmZ 	 d dlmZ  ee      Zd Zd Zd Zd
dZd	 Zy# e	$ r	 d dl
mZ Y &w xY w)    N)Path)tqdm)versionc                    dd l }|j                  j                  d      }d}| d   rt        t	        t        | d         j                  d                  D ]z  }t        | d         t        |j                        dz   z  }|j                  j                  t        |            }|j                  t        |      |	       |j                  d       | nt        d
      }t        | d         j                         }t        | d         j                         }|j                  j                  t        |            }|j                  t        |      |	       |j                  d       |j                  d
       |s|j                          y y )Nr   zWord.Application   batchinput*.docxoutput.pdf)
FileFormat   total)win32com.clientclientDispatchr   sortedr   globstrstem	DocumentsOpenSaveAsCloseresolveupdateQuit)	pathskeep_activewin32comwordwdFormatPDFdocx_filepathpdf_filepathdocpbars	            N/var/www/html/answerous/venv/lib/python3.12/site-packages/docx2pdf/__init__.pywindowsr)      s=   ??##$67DKW~!&eGn)=)B)B8)L"MN 	Mh0C8J8J4Kf4TUL..%%c-&89CJJs<([JAIIaL		 !}U7^,446E(O,446nn!!#m"45

3|$
=		!A		     c           	      N   t        t              j                  dz  j                         }dddt	        |      t	        | d         t	        | d         t	        |      j                         g}d }| d   r/t        t        t        | d         j                  d	                  nd
}t        |      } ||      D ][  }	 t        j                  |      }|d   dk(  r|j                  d
       3|d   dk(  s<t        |       t        j                   d
       ] y # t        $ r Y jw xY w)Nzconvert.jxaz/usr/bin/osascriptz-l
JavaScriptr	   r   c              3      K   t        j                  | t         j                        }	 |j                  j	                         j                         }|sy |j                  d       ?w)N)stderrzutf-8)
subprocessPopenPIPEr.   readlinerstripdecode)cmdprocesslines      r(   runzmacos.<locals>.run5   sT     ""3z?>>**,335D++g&&	 s   A&A(r   r
   r   r   resultsuccesserror)r   __file__parentr   r   lowerlenlistr   r   jsonloads
ValueErrorr   printsysexit)	r   r    scriptr5   r8   r   r'   r7   msgs	            r(   macosrI   )   s   8n##m3<<>FFE'NE(OK C' ?DGnCT%.)..x89:RSEeDC 		**T"C x=I%KKN]g%#JHHQK	  		s   =D	D$#D$c                 v   t        |       j                         } |rt        |      j                         nd }i }| j                         r9d|d<   t        |       |d<   |r|j                         sJ t        |       }||d<   |S d|d<   t        |       j	                  d      sJ t        |       |d<   |r5|j                         r%t        |t        | j
                        dz   z        }nL|rt        |      j	                  d      s0J t        | j                  t        | j
                        dz   z        }||d<   |S )NTr   r	   r   Fz.docxr   )r   r   is_dirr   endswithr   r=   )
input_pathoutput_pathr   s      r(   resolve_pathsrO   K   s+   j!))+J1<${#++-$KFwj/w%%'''j/K&x M  w:''000j/w;--/kS-AF-JKLK{#,,V444j//3z3G&3PQRK&xMr*   c                     t        | |      }t        j                  dk(  rt        ||      S t        j                  dk(  rt	        ||      S t        d      )Ndarwinwin32zSdocx2pdf is not implemented for linux as it requires Microsoft Word to be installed)rO   rE   platformrI   r)   NotImplementedError)rM   rN   r    r   s       r(   convertrU   e   sP    *k2E
||xUK((		 uk**!a
 	
r*   c                  p   dd l } dd ldt        j                  v r$t	        t
               t        j                  d       | j                  d      }fd}j                  ||      }|j                  dd       |j                  d	d
d       |j                  dddd       |j                  dddd       t        t        j                        dk(  r&|j                          t        j                  d       n|j                         }t        j                  |j                  |j                          y )Nr   z	--versiona:  
    Example Usage:

    Convert single docx file in-place from myfile.docx to myfile.pdf:
        docx2pdf myfile.docx

    Batch convert docx folder in-place. Output PDFs will go in the same folder:
        docx2pdf myfolder/

    Convert single docx file with explicit output filepath:
        docx2pdf input.docx output.docx

    Convert single docx file and output to a different explicit folder:
        docx2pdf input.docx output_dir/

    Batch convert docx folder. Output PDFs will go to a different explicit folder:
        docx2pdf input_dir/ output_dir/
    c                 *    j                  | d      S )N    )max_help_position)RawDescriptionHelpFormatter)progargparses    r(   <lambda>zcli.<locals>.<lambda>   s    8#G#G $H $ r*   )descriptionformatter_classr	   zIinput file or folder. batch converts entire folder or convert single file)helpr   ?zoutput file or folder)nargsr`   z--keep-active
store_trueFz%prevent closing word after conversion)actiondefaultr`   zdisplay version and exitr   )textwrapr\   rE   argvrD   __version__rF   dedentArgumentParseradd_argumentr?   
print_help
parse_argsrU   r	   r   r    )rf   r^   r_   parserargsr\   s        @r(   clirp   q   s    chhk//	K*O $$ % F X   2IJ
4	   L%>X   388}  "DJJT%5%56r*   )NF)rE   rA   r/   pathlibr   	tqdm.autor   importlib.metadatar   ImportErrorimportlib_metadata__package__rh   r)   rI   rO   rU   rp    r*   r(   <module>rx      sW    
    +* k"2D4	
97O  +*+s   9 AA