
    Пie                         d dl mZmZ d dlmZmZ d dlmZ d dlZd dl	Z	d dl
mZ d dlmZ d dlZd dlZd dlZd dlZd dlZ eddg	      Zej)                  d
      defd       Zej-                  d      defd       Zy)    )	APIRouterstatus)JSONResponseFileResponse)EditDocumentRequestN)Path)Documentz
/documents	Documents)prefixtagsz/createrequestc           
        K   	 t        d      }|j                         st        t        j                  ddd d      S d| j
                  j                  dd       dt        j                         j                  d d	  d
}t        d      |z  }	 t        j                  |      }g }d}t        t        |            D ]Q  }||   }|j                  d      }	|	r|j                  d|dz           |	D ]  }
|j!                  |
d       |j#                          t        j$                  |
j&                  |
j(                  |
j*                  |
j,                        }|j/                  || j
                  dddd      }|dk  s|j1                  |
j&                  |
j,                  dz
  f| j
                  ddd        d}|j                  d| j
                          |j3                         }|j                  d|dz    dt        |       d       T |j5                  |       |j7                          t9        t;        |      |d      S # t<        $ r5}t        t        j>                  dd t;        |       d d      cY d }~S d }~ww xY w# t<        $ r5}t        t        j>                  dd!t;        |       d d      cY d }~S d }~ww xY ww)"Nz=files/original_student_files/AUTORIZACION_EVALUACION_2010.pdf  z Documento original no encontrador   messagedatastatus_codecontentautorizacion_ _   z.pdffiles/original_student_filesFz[STUDENT_NAMES]u&   ENCONTRADO [STUDENT_NAMES] en página    )r   r   r   )fill
   )r   r   r   r   T)fontsizecoloralignoverlay   )r   r   r!   zREEMPLAZADO con: u   Página z: z caracteresapplication/pdfpathfilename
media_type  zError procesando el documento: zError general: ) r   existsr   r   HTTP_404_NOT_FOUNDstudent_namereplaceuuiduuid4hexfitzopenrangelen
search_forappendadd_redact_annotapply_redactionsRectx0y0x1y1insert_textboxinsert_textget_textsavecloser   str	ExceptionHTTP_500_INTERNAL_SERVER_ERROR)r   original_fileunique_filenameoutput_filepdf_documentcontent_infofound_and_modifiedpage_numpagetext_instancesrect	text_rectrc	page_text	doc_errores                   ]C:\Users\jesus\OneDrive\Escritorio\proyecto_pie360\backend\app\backend\routers\word_editor.pyedit_documentrU      s    f
\]##%"55!A   *'*>*>*F*FsC*P)QQRSWS]S]S_ScScdfefSgRhhlm9:_LI	99]3LL!& "#l"34 ,\#H- "&1B!C! ''*PQY\]Q]P^(_` !/ --d-C--/ %)IIdggtww$Q	 "00%#00%'"+"#$( 1  6 ,,!%$''A+ 6 ' 4 4)+&/(, - +: *.& ''*;G<P<P;Q(RS !MMO	##hx!|nBs9~>Nk$Z[Y,\^ k*   %(,   	"AA!!@Y@PQ  	  
==,SVH5
 	

sw   K9J
 KAJ
 C/I	 ?C	I	 K		J*J<J=J
 KJJ
 
	K*K=K>KKKz/download/{filename}r&   c           	      6  K   	 t        d      | z  }|j                         st        t        j                  ddd d      S t        t        |      | d      S # t        $ r5}t        t        j                  dd	t        |       d d      cY d }~S d }~ww xY ww)
Nr   r   zArchivo no encontrador   r   r#   r$   r(   zError descargando archivo: )	r   r)   r   r   r*   r   rB   rC   rD   )r&   	file_pathrS   s      rT   download_documentrX      s     
788C	!"55!6   Y(
 	
  
==8QA
 	

s@   B<A  BA B	B!*BBBBB)fastapir   r   fastapi.responsesr   r   app.backend.schemasr   osr-   pathlibr   docxr	   docx2txtshutilPyPDF2r0   io	documentspostrU   getrB   rX        rT   <module>rh      s    % 8 3 	        	
	
 	i
 i
 i
V %&

 '
rg   