如何使用DOMPDF中的PHP表文件生成PDF

时间:2018-11-24 01:42:09

标签: php html-table report dompdf export-to-pdf

我有这张桌子:

table with icon, CSS and dynamic variables

我想像报告一样使用DOMPDF进行渲染,但是我已经尝试过了,这就是我到目前为止得到的:

rendered PHP table in PDF file with DOMPDF

图标和其他东西没用,但我希望显示数据 我试图将输出的html数据导出到带有数组的另一个页面,但是它也不起作用。 有人知道如何从此表中创建体面的报告吗?

表格代码(无分页):

<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>

PDF生成器的代码:

<?php
ob_start();

include_once ("saude.php");

$html = ob_get_contents();

ob_end_clean();

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

use Dompdf\Dompdf;

$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;
?>

0 个答案:

没有答案