How to generate a PDF with PHP table file in DOMPDF












0















I have this following table:



table with icon, CSS and dynamic variables



I want to render it with DOMPDF like a report, but I've tried and this is what I got so far:



rendered PHP table in PDF file with DOMPDF



The icons and stuff are useless, but I want the data to be appearing
I've tried to export the output html data to another page with arrays but it doesn't work either.
Doe someone know how create a decent report from this table?



Code of the table (without pagination):



<table id="minhatabela" class="table table-user-information" style="font-size: 13px;">
<thead>
<tr>
<th></th>
<th>Nome <a onClick="changeIconNome()" style="color: #428bca;"><i onclick="sortTable(1)" class="fas fa-sort" id="icon_nome"></i></a></th>
<th>Data Nascimento </th>
<th>Serviço <a onClick="changeIconServico()" style="color: #428bca;"><i onclick="sortTable(3)" class="fas fa-sort" id="icon_servico"></i></a></th>
<th>Observação <a onClick="changeIconObs()" style="color: #428bca;"><i onclick="sortTable(4)" class="fas fa-sort" id="icon_obs"></i></a></th>
<th>Projeto terapêutico <a onClick="changeIconProj()" style="color: #428bca;"><i onclick="sortTable(5)" class="fas fa-sort" id="icon_proj"></i></a></th>
<th>Profissional Referente <a onClick="changeIconProf()" style="color: #428bca;"><i onclick="sortTable(6)" class="fas fa-sort" id="icon_prof"></i></a></th>
<?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "<!--";?>
<th>Opções</th>
<?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "-->";?>
</tr>
</thead>
<tbody id="myTable">
<tr>
<td>
<center><a class="linklink" href="<?php echo $espe; ?>?id=<?php echo $linha['id_usuario']?>"><i class="fas fa-info" title="Mais informações" style="color:black;">&nbsp;&nbsp;&nbsp;</i></a></center>
</td>
<td>
<?php echo $linha['nome']?>
</td>
<td>
<?php echo $linha['dia']."/".$linha['mes']."/".$linha['ano'] ?>
</td>
<td>
<?php echo $linha['servico'] ?>
</td>
<td>
<?php echo $linha['obs'] ?>
</td>
<td>
<?php echo $linha['ptspts'] ?>
</td>
<td>
<?php echo $linha['profissional'] ?>
</td>
<?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ){echo "<!--";} ?>
<td>
<center>
<a href="altera_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-edit' title="Alterar"></i></a>
<a href="exclui_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-trash-alt' title="Excluir"></i></a>
</center>
</td>
<?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ) echo "-->";?>

</tr>
</tbody>

</table>


Code of the PDF generator:



<?php
ob_start();

include_once ("saude.php");

$html = ob_get_contents();

ob_end_clean();

require_once 'assets/dompdf/autoload.inc.php';

use DompdfDompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$pdf = $dompdf->output();
$dompdf->stream();

header('Content-type: application/pdf; charset=utf-8');
echo $pdf;
?>









share|improve this question





























    0















    I have this following table:



    table with icon, CSS and dynamic variables



    I want to render it with DOMPDF like a report, but I've tried and this is what I got so far:



    rendered PHP table in PDF file with DOMPDF



    The icons and stuff are useless, but I want the data to be appearing
    I've tried to export the output html data to another page with arrays but it doesn't work either.
    Doe someone know how create a decent report from this table?



    Code of the table (without pagination):



    <table id="minhatabela" class="table table-user-information" style="font-size: 13px;">
    <thead>
    <tr>
    <th></th>
    <th>Nome <a onClick="changeIconNome()" style="color: #428bca;"><i onclick="sortTable(1)" class="fas fa-sort" id="icon_nome"></i></a></th>
    <th>Data Nascimento </th>
    <th>Serviço <a onClick="changeIconServico()" style="color: #428bca;"><i onclick="sortTable(3)" class="fas fa-sort" id="icon_servico"></i></a></th>
    <th>Observação <a onClick="changeIconObs()" style="color: #428bca;"><i onclick="sortTable(4)" class="fas fa-sort" id="icon_obs"></i></a></th>
    <th>Projeto terapêutico <a onClick="changeIconProj()" style="color: #428bca;"><i onclick="sortTable(5)" class="fas fa-sort" id="icon_proj"></i></a></th>
    <th>Profissional Referente <a onClick="changeIconProf()" style="color: #428bca;"><i onclick="sortTable(6)" class="fas fa-sort" id="icon_prof"></i></a></th>
    <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "<!--";?>
    <th>Opções</th>
    <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "-->";?>
    </tr>
    </thead>
    <tbody id="myTable">
    <tr>
    <td>
    <center><a class="linklink" href="<?php echo $espe; ?>?id=<?php echo $linha['id_usuario']?>"><i class="fas fa-info" title="Mais informações" style="color:black;">&nbsp;&nbsp;&nbsp;</i></a></center>
    </td>
    <td>
    <?php echo $linha['nome']?>
    </td>
    <td>
    <?php echo $linha['dia']."/".$linha['mes']."/".$linha['ano'] ?>
    </td>
    <td>
    <?php echo $linha['servico'] ?>
    </td>
    <td>
    <?php echo $linha['obs'] ?>
    </td>
    <td>
    <?php echo $linha['ptspts'] ?>
    </td>
    <td>
    <?php echo $linha['profissional'] ?>
    </td>
    <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ){echo "<!--";} ?>
    <td>
    <center>
    <a href="altera_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-edit' title="Alterar"></i></a>
    <a href="exclui_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-trash-alt' title="Excluir"></i></a>
    </center>
    </td>
    <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ) echo "-->";?>

    </tr>
    </tbody>

    </table>


    Code of the PDF generator:



    <?php
    ob_start();

    include_once ("saude.php");

    $html = ob_get_contents();

    ob_end_clean();

    require_once 'assets/dompdf/autoload.inc.php';

    use DompdfDompdf;

    $dompdf = new Dompdf();
    $dompdf->loadHtml($html);
    $dompdf->setPaper('A4', 'landscape');
    $dompdf->render();
    $pdf = $dompdf->output();
    $dompdf->stream();

    header('Content-type: application/pdf; charset=utf-8');
    echo $pdf;
    ?>









    share|improve this question



























      0












      0








      0








      I have this following table:



      table with icon, CSS and dynamic variables



      I want to render it with DOMPDF like a report, but I've tried and this is what I got so far:



      rendered PHP table in PDF file with DOMPDF



      The icons and stuff are useless, but I want the data to be appearing
      I've tried to export the output html data to another page with arrays but it doesn't work either.
      Doe someone know how create a decent report from this table?



      Code of the table (without pagination):



      <table id="minhatabela" class="table table-user-information" style="font-size: 13px;">
      <thead>
      <tr>
      <th></th>
      <th>Nome <a onClick="changeIconNome()" style="color: #428bca;"><i onclick="sortTable(1)" class="fas fa-sort" id="icon_nome"></i></a></th>
      <th>Data Nascimento </th>
      <th>Serviço <a onClick="changeIconServico()" style="color: #428bca;"><i onclick="sortTable(3)" class="fas fa-sort" id="icon_servico"></i></a></th>
      <th>Observação <a onClick="changeIconObs()" style="color: #428bca;"><i onclick="sortTable(4)" class="fas fa-sort" id="icon_obs"></i></a></th>
      <th>Projeto terapêutico <a onClick="changeIconProj()" style="color: #428bca;"><i onclick="sortTable(5)" class="fas fa-sort" id="icon_proj"></i></a></th>
      <th>Profissional Referente <a onClick="changeIconProf()" style="color: #428bca;"><i onclick="sortTable(6)" class="fas fa-sort" id="icon_prof"></i></a></th>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "<!--";?>
      <th>Opções</th>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "-->";?>
      </tr>
      </thead>
      <tbody id="myTable">
      <tr>
      <td>
      <center><a class="linklink" href="<?php echo $espe; ?>?id=<?php echo $linha['id_usuario']?>"><i class="fas fa-info" title="Mais informações" style="color:black;">&nbsp;&nbsp;&nbsp;</i></a></center>
      </td>
      <td>
      <?php echo $linha['nome']?>
      </td>
      <td>
      <?php echo $linha['dia']."/".$linha['mes']."/".$linha['ano'] ?>
      </td>
      <td>
      <?php echo $linha['servico'] ?>
      </td>
      <td>
      <?php echo $linha['obs'] ?>
      </td>
      <td>
      <?php echo $linha['ptspts'] ?>
      </td>
      <td>
      <?php echo $linha['profissional'] ?>
      </td>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ){echo "<!--";} ?>
      <td>
      <center>
      <a href="altera_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-edit' title="Alterar"></i></a>
      <a href="exclui_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-trash-alt' title="Excluir"></i></a>
      </center>
      </td>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ) echo "-->";?>

      </tr>
      </tbody>

      </table>


      Code of the PDF generator:



      <?php
      ob_start();

      include_once ("saude.php");

      $html = ob_get_contents();

      ob_end_clean();

      require_once 'assets/dompdf/autoload.inc.php';

      use DompdfDompdf;

      $dompdf = new Dompdf();
      $dompdf->loadHtml($html);
      $dompdf->setPaper('A4', 'landscape');
      $dompdf->render();
      $pdf = $dompdf->output();
      $dompdf->stream();

      header('Content-type: application/pdf; charset=utf-8');
      echo $pdf;
      ?>









      share|improve this question
















      I have this following table:



      table with icon, CSS and dynamic variables



      I want to render it with DOMPDF like a report, but I've tried and this is what I got so far:



      rendered PHP table in PDF file with DOMPDF



      The icons and stuff are useless, but I want the data to be appearing
      I've tried to export the output html data to another page with arrays but it doesn't work either.
      Doe someone know how create a decent report from this table?



      Code of the table (without pagination):



      <table id="minhatabela" class="table table-user-information" style="font-size: 13px;">
      <thead>
      <tr>
      <th></th>
      <th>Nome <a onClick="changeIconNome()" style="color: #428bca;"><i onclick="sortTable(1)" class="fas fa-sort" id="icon_nome"></i></a></th>
      <th>Data Nascimento </th>
      <th>Serviço <a onClick="changeIconServico()" style="color: #428bca;"><i onclick="sortTable(3)" class="fas fa-sort" id="icon_servico"></i></a></th>
      <th>Observação <a onClick="changeIconObs()" style="color: #428bca;"><i onclick="sortTable(4)" class="fas fa-sort" id="icon_obs"></i></a></th>
      <th>Projeto terapêutico <a onClick="changeIconProj()" style="color: #428bca;"><i onclick="sortTable(5)" class="fas fa-sort" id="icon_proj"></i></a></th>
      <th>Profissional Referente <a onClick="changeIconProf()" style="color: #428bca;"><i onclick="sortTable(6)" class="fas fa-sort" id="icon_prof"></i></a></th>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "<!--";?>
      <th>Opções</th>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 && $linhass['id_area'] != 4) echo "-->";?>
      </tr>
      </thead>
      <tbody id="myTable">
      <tr>
      <td>
      <center><a class="linklink" href="<?php echo $espe; ?>?id=<?php echo $linha['id_usuario']?>"><i class="fas fa-info" title="Mais informações" style="color:black;">&nbsp;&nbsp;&nbsp;</i></a></center>
      </td>
      <td>
      <?php echo $linha['nome']?>
      </td>
      <td>
      <?php echo $linha['dia']."/".$linha['mes']."/".$linha['ano'] ?>
      </td>
      <td>
      <?php echo $linha['servico'] ?>
      </td>
      <td>
      <?php echo $linha['obs'] ?>
      </td>
      <td>
      <?php echo $linha['ptspts'] ?>
      </td>
      <td>
      <?php echo $linha['profissional'] ?>
      </td>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ){echo "<!--";} ?>
      <td>
      <center>
      <a href="altera_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-edit' title="Alterar"></i></a>
      <a href="exclui_saude_lista.php?id_usuario=<?php echo $linha['id_usuario'] ?>" style="color: #428bca;"><i class='far fa-trash-alt' title="Excluir"></i></a>
      </center>
      </td>
      <?php if($linhass['id_area'] != 1 && $linhass['id_area'] != 5 ) echo "-->";?>

      </tr>
      </tbody>

      </table>


      Code of the PDF generator:



      <?php
      ob_start();

      include_once ("saude.php");

      $html = ob_get_contents();

      ob_end_clean();

      require_once 'assets/dompdf/autoload.inc.php';

      use DompdfDompdf;

      $dompdf = new Dompdf();
      $dompdf->loadHtml($html);
      $dompdf->setPaper('A4', 'landscape');
      $dompdf->render();
      $pdf = $dompdf->output();
      $dompdf->stream();

      header('Content-type: application/pdf; charset=utf-8');
      echo $pdf;
      ?>






      php html-table report dompdf export-to-pdf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 10:09









      Brian Tompsett - 汤莱恩

      4,2231338101




      4,2231338101










      asked Nov 24 '18 at 1:42









      Leonardo GnutzmannLeonardo Gnutzmann

      11




      11
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454483%2fhow-to-generate-a-pdf-with-php-table-file-in-dompdf%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454483%2fhow-to-generate-a-pdf-with-php-table-file-in-dompdf%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Tonle Sap (See)

          I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

          Guatemaltekische Davis-Cup-Mannschaft