1

Estoy tratando de generar un documento pdf que rellene ciertos campos con variables en php pero al momento de hacer echo en el html se muestra pero cuando quiero visualizarlo como PDF con la libreria DOMPDF no se muestra esta variable.

Aquí está mi código:

   <?php

error_reporting(E_ERROR | E_PARSE);

ob_start();

$nombreCliente = "< NOMBRE O RAZON SOCIAL DEL CLIENTE >";

?>
<html>
<head>
    <title>Prueba generador de PDF</title>
    <link rel="stylesheet" href="http://<?php echo $_SERVER['HTTP_HOST'];?>/Prueba/css/style.css">
</head>
<body>
    <img class="logo" src="http://<?php echo $_SERVER['HTTP_HOST'];?>/Prueba/imgs/kabale-logo.jpg">
    <h1 class="centrado"> Contrato de Servicio </h1>
    <h2 class="centrado no-interlineado"> UINOM</h2>
    <p style="text-align: justify">
    CONTRATO DE PRESTACION DE SERVICIOS DE VERIFICACION DE INFORMACION COMERCIAL QUE CELEBRAN POR UNA PARTE <b>- 
    UNIDAD DE INSPECCION S.A. DE CV.</b>, EN LO SUCESIVO DENOMINADO COMO <b>“-”</b> Y POR LA OTRA PARTE <?php echo  $nombreCliente ; ?> 
    EN LO SUCESIVO DENOMINADO COMO “EL CLIENTE”, AL AMPARO DE LAS SIGUIENTES DECLARACIONES. Y CLAUSULAS:
    </p>
</body>
</html>

<?php 

$html = ob_get_clean();
//echo $html;
require_once 'libreria/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$options = $dompdf->getOptions();
$options->set(array('isRemoteEnabled' => true));
$dompdf->setOptions($options);
$dompdf->loadHTML($html);

$dompdf->setPaper('letter');
//dompdf->setPaper('A4', 'landscape');
$dompdf->render();
//Attachment false es para que no se descargue, true es para descargar automaticamente
$dompdf->stream("archivo_.pdf", array("Attachment" => false));


?>

Y asi se muestra cuando descomento el echo $html; y comento la linea de: $dompdf->stream("archivo_.pdf",array("Attachment => false"))

Pagina en HTML donde se muestra el valor de la variable

Pero cuando genero el pdf se muestra sin el valor de la variable:

1 respuesta 1

1

Ya vi, se tenia que habilitar el procesamiento de HTML5, se hace de la siguiente manera:

$options->setIsHtml5ParserEnabled(true);

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.