Quantcast
Channel: Preguntas activas con las etiquetas phpword - Stack Overflow en español
Viewing all articles
Browse latest Browse all 27

El documento se corrompe al agregar imágenes en PhpWord

$
0
0

Estoy trabajando con la biblioteca PHPWord de PHPOffice con plantillas y estoy teniendo un problema.

El detalle ocurre al generar un documento Word. Todo bien al hacer los reemplazos de texto, pero cuando quiero agregar imágenes (con el método setImageValue()) el documento generado no puede abrirse.

He buscado la forma de habilitar la depuración, pero no puedo encontrarla. También tengo la sospecha de que el error puede ser generado por las dimensiones y peso de las imágenes, pero ya intenté modificando con width, height y ratio.

Les comparto mi código:

<?phprequire_once $_SERVER['DOCUMENT_ROOT'] . "/assets/php/phpoffice/phpword/vendor/autoload.php";$filename = "Historia_Clinica_$whapp.docx";header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;');header('Content-Disposition: attachment; filename="' . $filename . '"');$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("templates/Historia_Clinica.docx");$templateProcessor->setValue("fechaExpediente", $respuesta_fecha_expediente);$templateProcessor->setValue("nombre",          $respuesta_nombre);$templateProcessor->setValue("motivo",          $respuesta_motivo);$templateProcessor->setValue("enfermedades",    $respuesta_enfermedades);$templateProcessor->setValue("alergias",        $respuesta_alergias);$templateProcessor->setValue("medicamentos",    $respuesta_medicamentos);$templateProcessor->setValue("edad",            $respuesta_edad);$templateProcessor->setValue("fechaNacimiento", $respuesta_fecha_nacimiento);$templateProcessor->setValue("estadoCivil",     $respuesta_estado_civil);$templateProcessor->setValue("ocupacion",       $respuesta_ocupacion);$templateProcessor->setValue("direccion",       $respuesta_direccion);$templateProcessor->setValue("celular",         $whapp);$templateProcessor->setValue("recomendado",     $respuesta_recomendado);$select = $con->select("chats_mensajes", "Id_Chat_Mensaje");$select->innerjoin("chats USING(Id_Chat)");$select->where("Whapp", "=", $whapp);$select->where_and("Mensaje", "=", "IMAGE");$selection = $select->execute();foreach ($selection as $x => $image) {    if ($x > 7) {        $x = 7;        break;    }    $id_chat_mensaje = $image["Id_Chat_Mensaje"];    // $templateProcessor->setValue("imagen$x", "img/messages/$id_chat_mensaje.jpg"); #Con esta línea confirme que mis documentos si estaban siendo generados y que las rutas eran correctas.    $templateProcessor->setImageValue("imagen$x", "img/messages/$id_chat_mensaje.jpg");}if ($x == count($selection) - 1 && $x < 7) {    for ($i = $x + 1; $i < 8; $i++) {        $templateProcessor->setValue("imagen$i", "");    }}$templateProcessor->saveAs("php://output");?>

Viewing all articles
Browse latest Browse all 27

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>