+
    nkj!5                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt  ! R R]	4      t
0 Rmt0 RmtR tR tRR ltR tR	 tR
 tR tR tR tR tRRR^x/R ltR# )    N)Pathc                   6   a a ] tR t^t oRV 3R lltRtVtV ;t# )ConversionErrorc                2   < \         SV `  V4       W n        R # )N)super__init__status)selfmessager	   	__class__s   &&&-/opt/render/project/src/conversion_service.pyr   ConversionError.__init__   s    !    )r	   )i  )__name__
__module____qualname____firstlineno__r   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r   r      s      r   r   c                    R RRRRRRRRRRRRR/pV'       g   \        R4      hW9   d;   VP                  W ,          4      '       g   \        RV P                  4        R	24      hV R9   d    \        P                  ! \
        P                  ! V4      4      ;_uu_ 4       pVP                  4       p\        ;QJ d    R
 V 4       F  '       g   K   RM	  RM! R
 V 4       4      '       d   \        R4      hRV9  d   \        RV P                  4        R	24      h RRR4       R# R#   + '       g   i     R# ; i  \        P                   d$   p\        RT P                  4        R	24      ThRp?ii ; i)pdfzipjpgjpegpnggifbmpzThe uploaded file is empty.z!The uploaded file is not a valid z file.c              3      "   T F5  qP                  R 4      ;'       g    R\        V4      P                  9   x  K7  	  R# 5i)/z..N)
startswithr   parts).0names   & r   	<genexpr>_validate.<locals>.<genexpr>*   s3     ZTYDs+GGttDz7G7G/GGTYs   ?!?TFz,The uploaded document contains unsafe paths.[Content_Types].xmlN)s   %PDF-)s   PKs   PKs   PK)s   )s   PNG

)s   GIF87as   GIF89a)s   BM>   odpodsodtdocxpptxxlsx)
r   r"   upperzipfileZipFileioBytesIOnamelistany
BadZipFile)sourcecontent
signaturesarchivenamesexcs   &&    r   	_validater=      sX   {<!"&%xJ ;<<G$6$6z7I$J$J A&,,.AQQWXYY>>	gG!455((*3ZTYZ333ZTYZZZ)*XYY(5),MfllnM]]c*dee 6	 65 ?555 !! 	g!$EfllnEUU["\]cff	gsB   ,2D9 -D%D%)/D%D9 %D6	0D9 6D9 9E1E,,E1c                 l   . p\         P                  P                  R 4      pV'       d%   VP                  \	        V4      V  R2,          4       \
        P                  ! V 4      pV'       d   VP                  \	        V4      4       \	        \         P                  P                  RR4      4      R,          R,          R,          pVP                  4       '       d%   VP                  VP                  RV  R24      4       V F&  pVP                  4       '       g   K  \        V4      u # 	  \        RR	4      h)
POPPLER_BIN_PATHz.exeLOCALAPPDATA 	MicrosoftWinGetPackagesz*Poppler*/*/Library/bin/+This conversion is temporarily unavailable.  )osenvirongetappendr   shutilwhichis_dirextendglobis_filestrr   )r%   
candidates
configuredpathwinget_root	candidates   &     r   _toolrW   2   s    J 23J$z*vT]:;<<D$t*%rzz~~nb9:[H8SV``K+**-EdV4+PQR	y>!   G
MMr   c                     R p \         P                  ! V RRVVR7      pVP                  VR7      w  rVTP                  '       d7   \        P                  ! R
TRR  P                  RR7      4       \        RR4      hR #   \         P                   d;   pT'       d!   TP	                  4        TP                  4        \        RR4      ThR p?i\         d)   p\        P                  ! R4       \        RR	4      ThR p?ii ; i)NTF)capture_outputshellcwdenv)timeoutzConversion timed out.i  z"Conversion process could not startrE   rF   zConversion failed: %sreplace)errorsz The file could not be converted.  i0)
subprocessPopencommunicateTimeoutExpiredkillr   OSErrorlogging	exception
returncodeerrordecode)commandr]   r[   environmentprocessstdoutstderrr<   s   &&&&    r   _runrq   C   s    G[""
 !,,W,= -vef~/D/DI/D/VW@#FF  $$ ELLN!5s;D [>?KSQWZZ[s)   /A= =C=5CC=C=#C88C=c                    \         P                  ! R R7      ;_uu_ 4       p\        V4      pVRV  2,          pVR,          pVR,          p	VP                  4        V	P                  4        VP	                  V4       \        V4      P                  4       p
V
P                  pRpV
P                  P                  4       R9   dH   \        \        R4      P                  4      pV RVP                  RR	4       2VR&   R
VR,           2VR&   VRV	P                  4        2RRRRRRRVR\        V4      \        V4      .p\        WWR7       VRV 2,          pVP!                  4       '       d    VP#                  4       P$                  ^ 8X  d   \'        RR4      hVP)                  4       uuRRR4       #   + '       g   i     R# ; i)convert-hau-prefixzinput.outputprofileNrG   ;PATHrA   zvnd.sun.star.pathname:zfundamental.iniURE_BOOTSTRAPz-env:UserInstallation=z
--headlessz--nologoz--nodefaultz--nofirststartwizardz--norestorez--nolockcheckz--convert-toz--outdir)r[   rm   )The conversion engine produced no output.r`   >   soffice.comsoffice.exe)tempfileTemporaryDirectoryr   mkdirwrite_bytesresolveparentr%   lowerdict
__import__rH   rI   as_urirQ   rq   rP   statst_sizer   
read_bytes)r7   targetr8   
executabler]   folderroot
input_path
output_dirrw   executable_pathprogram_dirrm   rl   output_paths   &&&&&          r   _libreofficer   [   s   		$	$N	;	;vF|fVH--
H_
"w'z*224%,,%%'+IIz$/778K%0M;??623N2O"PK-CKRcDcCd+eK($W^^%5$67"FJ
O
 	W;H VF8#44""$$(8(8(:(B(Ba(G!"MsSS%%'A 
<	;	;	;s   FF..F?	c                 l    ^ RI Hp  TP	                  \
        P                  ! T4      4      P                  R4      p\
        P                  ! 4       pTP                  TRRR7       TP                  4       #   \         d   p\        RR4      ThRp?ii ; i  \         d   p\        R	R
4      ThRp?ii ; i)r   ImagerE   rF   NRGBPDFg     b@)format
resolution!The image could not be converted.r`   )PILr   ImportErrorr   openr2   r3   convertsavegetvalue	Exception)r7   r8   r]   r   r<   imagerv   s   &&&    r   
_image_pdfr      s    [Q

2::g./77>

6%E
:    [KSQWZZ[  QA3GSPQs/   A6 A,B 6BBBB3!B..B3c                     ^ RI Hp VP                  \        P                  ! V4      4      p\        P                  ! 4       pVR
9   d   RMVP                  4       pVR8X  d#   VP                  R9   d   VP                  R4      pVP                  WVR7       VP                  4       #   \         d   p\        RR4      ThRp?i\         d   p\        RR	4      ThRp?ii ; i)r   r   JPEGr   )r   rE   rF   Nr   r`   >   r   r   >   PLARGBA)r   r   r   r2   r3   r/   moder   r   r   r   r   r   )r7   r   r8   r   r   rv   format_namer<   s   &&&     r   _image_imager      s    Q

2::g./ &/ 9fv||~& UZZ3F%FMM%(E

6
.   [KSQWZZ QA3GSPQs*   B#B& &C1B>>CCCCc                    \        R 4      p\        P                  ! RR7      ;_uu_ 4       p\        V4      pVR,          pVR,          pVP	                  V4       \        VRRRRV  2\        V4      \        V4      .V4       VP                  R	V  24      pVP                  4       '       g   \        R
R4      hVP                  4       uuRRR4       #   + '       g   i     R# ; i)
pdftocairors   rt   	input.pdfpagez-singlefile-r150-.r{   r`   N)rW   r~   r   r   r   rq   rQ   with_suffixrP   r   r   )	r   r8   r]   toolr   r   source_pathru   r   s	   &&&      r   _pdf_imagesr      s    D		$	$N	;	;vF|[((dM4!F8c+>NPSTZP[\^ef((1VH6""$$!"MsSS%%' 
<	;	;	;s   BCC#	c                 r    VR 8X  d   V R9   d   V# \        RR4      hV R9   d
   VR9   d   V# \        RR4      h)txtz4Text extraction is not available for this file type.r`   z&This text conversion is not supported.>   mdr   markdown)r   )r7   r   r8   s   &&&r   _textr      sJ    ..NTVYZZ**v9R/R
BC
HHr   c           	      R   \        R 4      p\        P                  ! RR7      ;_uu_ 4       p\        V4      pVR,          pVR,          pVP	                  V 4       \        V\        V4      \        V4      .V4       VP                  4       uuRRR4       #   + '       g   i     R# ; i)	pdftotextrs   rt   r   z
output.txtN)rW   r~   r   r   r   rq   rQ   r   )r8   r]   r   r   r   r7   rv   s   &&     r   	_pdf_textr      s~    D		$	$N	;	;vF|#$7#dCKV-w7  " 
<	;	;	;s   ABB&	c                 z    ^ RI Hp \        P                  ! RR7      ;_uu_ 4       p\	        V4      pVR,          pVR,          pVP                  V 4       V! \        V4      4      p VP                  \        V4      ^ RR7       VP                  4        VP                  4       '       d;   VP                  4       P                  '       d   VP                  4       uuRRR4       # RRR4       \!        R	4      pR
p	\        P                  ! RR7      ;_uu_ 4       p\	        T4      pTR,          pTR,          p
TP                  T 4       \#        TRRR\        T4      \        T
4      .T4       \%        TP'                  R4      R R7      pT'       g   \)        RR4      h. p. p/ p\+        T^4       F  w  ppRT R2pRT 2pTP                  4       pTTT&   ^ RIHp TP1                  \2        P4                  ! T4      4      ;_uu_ 4       pTP6                  R,          pTP8                  R,          pRRR4       TP;                  RX RX RT RT RT RT R T R!T RT R"24       T\=        T4      8  d   TP;                  R#4       TP;                  R$T R%T R&24       K  	  \2        P4                  ! 4       p\>        P@                  ! TR'\>        PB                  4      ;_uu_ 4       pTPE                  R(R)4       TPE                  R*R+4       TPE                  R,R-R.PG                  T4      ,           R/,           4       TPE                  R0R1T	 R2R.PG                  T4       R324       TPI                  4        F  w  ppTPE                  R4T 2T4       K  	  RRR4       TPK                  4       uuRRR4       #   TP                  4        i ; i  + '       g   i     EL; i  \         d    \        P                  ! R4        ELi ; i  + '       g   i     EL; i  + '       g   i     L; i  + '       g   i     R# ; i)5r   )	Converterzconvert-hau-pdf2docx-rt   r   zoutput.docxN)startendzAEditable PDF-to-DOCX reconstruction failed; using visual fallbackr   ak  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"rs   r   z-pngr   r   z
page-*.pngc                 Z    \        V P                  P                  R ^4      ^,          4      # )r   )intstemrsplit)rT   s   &r   <lambda>_pdf_docx.<locals>.<lambda>   s"    TYYEUEUVY[\E]^_E`Aar   )keyz#The PDF renderer produced no pages.r`   r   z.pngrIdr   i5%  z0<w:p><w:r><w:drawing><wp:inline>
<wp:extent cx="z" cy="z"/><wp:docPr id="z" name="PDF page z"/>
<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic><pic:nvPicPr><pic:cNvPr id="z" name="z@"/><pic:cNvPicPr/></pic:nvPicPr>
<pic:blipFill><a:blip r:embed="zh"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill>
<pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="z"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr>
</pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p>z+<w:p><w:r><w:br w:type="page"/></w:r></w:p>z<Relationship Id="za" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/z"/>wr(   a  <?xml version="1.0" encoding="UTF-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/>
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>z_rels/.relsa  <?xml version="1.0" encoding="UTF-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
</Relationships>zword/_rels/document.xml.relszT<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">rA   z</Relationships>zword/document.xmlz3<?xml version="1.0" encoding="UTF-8"?>
<w:document z	><w:body>zc<w:sectPr><w:pgMar w:top="0" w:right="0" w:bottom="0" w:left="0"/></w:sectPr></w:body></w:document>zword/media/)&pdf2docxr   r~   r   r   r   rQ   r   closerP   r   r   r   r   rg   rh   rW   rq   sortedrO   r   	enumerater   r   r   r2   r3   widthheightrJ   lenr0   r1   ZIP_DEFLATEDwritestrjoinitemsr   )r8   r]   r   r   r   r7   rv   	converterr   
namespacesru   pagesdocument_partsrelationshipsmediaindexr   
image_namerelationship_idr   r   openedr   r   r:   r%   s   &&                        r   	_pdf_docxr      s   _&((0GHHF<DK'FM)Fw'!#f+.I"!!#f+QD!A!~~FKKM$9$9$9((* IHH" D	O  
	$	$N	;	;vF|#7#dFD%Vc&kBGLtyy.4ab!"GMM$UA.KE4 t,J #E7mOOO%E %E*!BJJu-..&t+- / !! 'wfVH$5eW<MeW U&&+WHZL A  /0 1227vh GK#N O s5z!%%&ST  $_$5 6!!+C1% /0 __VS'*>*>??72 5  ] -  ;  >T  WY  W^  W^  _l  Wm  >m  pB  >B  C0 7L	"''."9!:  ;^3a b${{}e  ;tf!5u=  - @   m 
<	;! ! IHH  _]^_@ /..& @?M 
<	;	;s   %O A O(N1%O+OO
O %O C/P)'P/B5P)$B+P	P)1OOO	O O !O?>O?P	P)P&!P))P:	libreoffice_pathr]   c                   V P                  4       P                  R 4      p VP                  4       P                  R 4      p\        W4       W8X  d   V# V \        9   d   V\        9   d   \	        WV4      # VR8X  d   V \        9   d   \        WV4      # V R8X  d"   VR9   d   \        VR8X  d   RW$4      # RW$4      # V R8X  d   VR8X  d   \        W$4      # V R8X  d   VR8X  d   \        W$4      # VR9   d   \        WV4      # V \        0 Rm,          9   d   V\        RR0,          9   g   V R8X  dg   VR8X  d`   T;'       g5    \        P                  ! R4      ;'       g    \        P                  ! R4      pV'       g   \        RR	4      h\        WW%V4      # \        R
V P                  4        RVP                  4        R2R4      h)r   r   r   r   r   r,   sofficelibreofficerE   rF   zConversion from z to z is not supported.r`   >   r   r   r   >   r   r   r   )r   lstripr=   IMAGE_FORMATSr   r   r   r   r   r   OFFICE_FORMATSrK   rL   r   r   r/   )r7   r   r8   r   r]   r   s   &&&$$ r   r   r     s   \\^""3'F\\^""3'Ff6]#:FG446]2&7336%;;FeO5RRRR6U?**6V+****VW--.#<<<>]bdi\jKjAju_6!1%__i)@__FLLQ^D_
!"OQTUUFGII
,V\\^,<D@PPbceh
iir   >   dochtmr)   r*   r+   pptrtfxlsr,   htmlr-   r.   >   r   r   r   r   tifr   tiffwebp)NN)r2   rg   rG   rK   ra   r~   r0   pathlibr   r   r   r   r   r=   rW   rq   r   r   r   r   r   r   r   r    r   r   <module>r      s    	  	     i  Lg4N"G0!(HQQ (I#R!jj js jr   