MPDF php class - How to display images within Tables

Asked

Viewed 465 times

0

In the code below, I intended to place an image inside the table displayed in PDF, but the image is not displayed and a box with "X" red. As I put the image "inside" the mysqli_fetch_assoc?

In the current code only appear images outside the while. There are some different image paths, because I’m testing - unsuccessfully - all possible paths.

Here’s the code:

<?php
    include ('pdf/mpdf.php');
 include('config.php'); session_start();
     $id=$_SESSION['id'];
 $tabela = '<img src=/bimbopnl/logo.png />';
$tabela .= '<br><br><br><br><br><br>';
 $tabela .= '<table  align=left>'; 
 $tabela .= '<tr>';
 $tabela .= '<td colspan="4" align="center"><br>Indicadores<br><br>
 </tr>';
 $tabela .= '</tr>';
 $tabela .= '<tr>';
      $tabela .= '<td><b>  Indicador  </b></td>';
    $tabela .= '<td><b>  Valor  </b></td>';
    $tabela .= '<td><b>  Meta  </b></td>';
    $tabela .= '<td><b>  Otimismo  </b></td>';
 $tabela .= '</tr>';
   $sql = mysqli_query($conexao,"SELECT * FROM tb_indicadores where  id='$id'     and dataIndicador='FEV - 2018' and tipoIndicador=1") or die(mysql_error()); 

 while($dados = mysqli_fetch_assoc($sql))
 { 

 $tabela .= '<tr>'; 

 $id=$dados['id'];
 $nome=$dados['nomeindicador'];
     $idind = $dados['idIndicador']; 
  $meta = $dados['meta']; 
  $otimismo = $dados['otimismo'];
  $dif = $valor/$meta;
imagem='';
   if($valor==''){$imagem= '/bimbopnl/imagens/semvalor.png';}   
   if(($otimismo=='otimista')&&($dif<=0.95)){$imagem= '/miniredup.png';}
    if(($otimismo=='pessimista')&&($dif<=0.95)){$imagem= 'bimbopnl/minireddown.png';}
  if(($otimismo=='otimista')&&($dif>0.9 && $dif<=0.95)){$imagem= 'bimbopnl/miniyellowup.png';}
  if(($otimismo=='pessimista')&&($dif>0.9 && $dif<=0.95)){$imagem= 'bimbopnl/miniyellowdown.png';} 
 if(($otimismo=='otimista')&&($dif>0.95 && $dif<=1.05)){$imagem= 'bimbopnl/minigreenup.png';}

 if(($otimismo=='pessimista')&&($dif>0.95 && $dif<=1.05)){$imagem= 'bimbopnl/minigreendown.png';}
   if(($otimismo=='otimista')&&($dif>1.05)){$imagem= 'bimbopnl/miniblueup.png';}
   if(($otimismo=='pessimista')&&($dif>1.05)){$imagem= 'bimbopnl/minibluedown.png';}       

       $tabela .= '<td>'.$dados['nomeindicador'].'</td>'; $tabela .= '<td>'.$dados['valorIndicador'].'</td>';
             $tabela .= '<td>'.$dados['meta'].'</td>';   $tabela .= '<img             src=/'.'"$imagem"'.'>';
       $tabela .= '</tr>';
 }

 $tabela .= '</table>';
$tabela .= '<img src=/bimbopnl/rent.png>';

  echo '<br>';    echo '<br>';  echo '<br>';
$arquivo = 'Cadastro01.pdf';
$mpdf = new mPDF();
$mpdf->WriteHTML($tabela);
$mpdf->Output($arquivo, 'I');

 ?>

I’m using the class MPDF to produce a pdf.

1 answer

0

Friend, create a html as you wish, consulting the information, displaying and assembling the tables, after that do as below:

$url = $pastaraiz . "admin/voucher-pdf.php?voucher=" . $_POST["reserva"] .
                    "&voucher_docificado=" . $voucher_docificado;

                $ch = curl_init();
                // set url
                curl_setopt($ch, CURLOPT_URL, $url);

                //return the transfer as a string
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

                // $output contains the output string
                $output1 = utf8_encode(curl_exec($ch));

                // close curl resource to free up system resources
                curl_close($ch);

                define('MPDF_PATH', '../mpdf60/');
                include (MPDF_PATH . 'mpdf.php');
                $mpdf = new mPDF();
                $mpdf->WriteCell($output1);
                $mpdf->WriteHTML($output1);
                $mpdf->Output('../VOUCHERS/' . $voucher_docificado . '.pdf', 'F');

Observing: "admin/voucher-pdf.php? voucher=111"; is the screen path to generate the pdf.

  • Hello Maicon. Thank you for the strength!

  • Errors have appeared concerning some files I do not have: Warning: include(../mpdf60/mpdf.php): failed to open stream: No such file or directory in C: xampp htdocs bimbopnl pdffev.php on line 121 Warning: include(): Failed Opening '.. /mpdf60/mpdf.php' for inclusion (include_path='C: xampp php PEAR') in C: xampp htdocs bimbopnl pdffev.php on line 121 Warning: fopen(../VOUCHERS/.pdf): failed to open stream: No such file or directory in C: xampp htdocs bimbopnl pdf mpdf.php line on 7485 mPDF error: Unable to create output file: .. /VOUCHERS/. pdf

  • I went to the origin of the class but did not find tb on the site :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.