0

I'm showing the result of a search in a PHP file. However when trying to display the data when generating the pdf document, this does not, does not recognize the variables, how could I do it? I am using the structure of an HTML. Currently generating some errors when trying to pass the file to PDF, the errors shown are syntax errors

    <?php


require_once APPPATH. '/third_party/dompdf/autoload.inc.php';

use Dompdf\Dompdf;

$html ='<html>

<head>
     <title>Porcentaje de Cias</title>
</head>
<body>

<h2 style="text-align:center;">Porcentaje de Citas</h2>
<br></br>
<br></br>

<div>
    <label>Fecha de Inicio:<?php echo $_GET['fecha_ini']; ?></label>
</div>

<div>
    <label>Fecha de termino: <?php echo $_GET['fecha_ter']; ?></label>
</div>

<div>
    <label>Jefe de Carrera: <?php echo $_GET['jc']; ?></label>

</div>

<br></br>
<br></br>
<br></br>
<div>
<img src=".img/logo-aiep.png">
<div>
<br></br>
<div style="top: -100px;">
<table style="border:1px solid red;width:100%;">
    <tr>
        <th style="text-align:center;">Motivo</th>
        <th style="text-align:center;">Cantidad</th>
        <th style="text-align:center;">Porcentaje</th>
    </tr>      


               <?php 

                foreach($consulta as $row)

                {?>

               <tr>
                  <td style="text-align:center;"><?php echo $row->descripcion_mot ;?></td>
                  <td style="text-align:center;"><?php echo $row->cantidad_motivos ;?></td>
                  <td style="text-align:center;"><?php echo $row->porcentaje ; echo '%'?></td>


               </tr>


           <?php }?>
                <tr>

                  <td style="text-align:center;">Totales</td>
                  <td style="text-align:center;"><?php foreach($total as $row){ echo $row->total; }  ?></td>
                  <td style="text-align:center;">100 % </td>

                </tr>
</table>
<div>

</body>
</html>
';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("Porcentaje de Citas.pdf", array("Attachment" => false));

exit(0);
?>
CristianOx21
  • 217
  • 1
  • 4
  • 16
  • 1
    you should be getting parse errors here. – Funk Forty Niner Oct 26 '17 at 01:09
  • yes, and indeed it does, because it does not recognize the variables when trying to pass it to pdf – CristianOx21 Oct 26 '17 at 01:11
  • Break down your string into chunks (especially those that are inside `foreach` statements) and use your variables like this https://stackoverflow.com/questions/5368890/mixing-php-variable-with-string-literal. Append everything at the end, i.e. before streaming to your `DOMPDF` instance – ton Oct 26 '17 at 02:03

0 Answers0