Jump to content
Fórum Script Brasil
  • 0

php -> pdf


Carlos Rocha

Question

Olá pessoal.

Tenho o código abaixo que transforma uma pagina html (gerada por php) em pdf.

Esta funcinando direitinho.

Estou usando o dompdf

Porem, eu gostaria de colocar, no pdf, um cabeçalho e um rodapé mas não achei nada do dompdf sobre cabeçalho e rodapé na net.

Gostaria que voces me ajudassem.

Segue meu código:

<?php 
ob_start();
session_start();
header('Content-Type: text/html; charset=utf-8'); 
include("../global/config/const.php"); 
include("../global/config/conexao.php");  
include("../global/funcoes_php/formata_cep.php");  
include("../global/funcoes_php/formata_tel.php");  
include("../global/funcoes_php/formata_cpf.php");  
include("../global/funcoes_php/formata_cnpj.php");  
include("../global/funcoes_php/formata_data.php");  
?>
<html>
<head>
<title><?=$titulo_admin;?></title>
<link href="../global/config/stilo.css" rel="stylesheet" type="text/css"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>

<?php
if ($acao == "gerapdf")
{
    $consulta_fornecedor="
                       SELECT razaosocial, nome
                       FROM fornecedores
                       WHERE id=$id
                        ";

            list($FORNECEDOR_RAZAOSOCIAL,$FORNECEDOR_NOME) = mysql_fetch_row($MySQL->query($consulta_fornecedor));
    
            $texto= "<table width=\"95%\" border=\"1\" align=\"center\">
                   <tr><td colspan=\"4\" align=\"center\">
                                      RELATÓRIO ANALÍTICO DE PEDIDOS FORNECEDOR $FORNECEDOR_RAZAOSOCIAL$FORNECEDOR_NOME 
                       </td></tr>
                 ";
            $texto.= "<tr><td colspan=\"4\" align=\"left\">DATA: ".formata_data($data_relatorio)."</td></tr>";

             $consulta_cliente="
                       SELECT DISTINCT(pc.id_cliente),cl.razaosocial, cl.nome 
                       FROM pedidos_cliente pc    
                       INNER JOIN pedidos pe ON pe.ID_PEDIDO = pc.id_pedido_cliente                       
                       INNER JOIN produtos pd ON pd.id = pe.ID_PRODUTO                       
                       INNER JOIN fornecedores fd ON fd.id = pd.fornecedor
                       INNER JOIN clientes cl ON cl.id = pc.id_cliente                                              
                       WHERE fd.id = $id and pc.data = '$data_relatorio'                     
                       ORDER BY cl.nome, cl.razaosocial
                   ";
                   
                    $texto.= "<tr>
                              <td align=\"center\" width=\"40%\">NOME DO PRODUTO</td>
                              <td align=\"center\" width=\"20%\">QUANTIDADE</td>
                              <td align=\"center\" width=\"20%\">preço UNITÁRIO</td>
                              <td align=\"center\" width=\"20%\">SEMI TOTAL</td>
                          </tr>
                       ";

            $consulta_cliente_query = $MySQL->query($consulta_cliente);
            while(list($cliente,$CLIENTE_RAZAOSOCIAL,$CLIENTE_NOME) = mysql_fetch_row($consulta_cliente_query))
            {
                 $texto.= "<tr><td colspan=\"4\" align=\"left\">$CLIENTE_RAZAOSOCIAL$CLIENTE_NOME</td></tr>";

                  $consulta_itens="
                                    SELECT
                                      pd.nome,
                                      pe.quantidade,
                                      pe.preco_uni,
                                      pe.semi_total
                                    FROM pedidos pe  
                                    INNER JOIN produtos pd ON pd.id=pe.ID_PRODUTO     
                                    INNER JOIN fornecedores fd ON fd.id=pd.fornecedor          
                                    INNER JOIN pedidos_cliente pc ON pc.id_pedido_cliente=pe.ID_PEDIDO          
                                    INNER JOIN clientes cl ON cl.id=pc.id_cliente     
                                    WHERE fd.id = $id and pc.data = '$data_relatorio' and pc.id_cliente=$cliente
                                    ORDER BY pe.ID_PRODUTO                  
                                 ";
                 $SUB_TOTAL=0.00;
                 $consulta_itens_query = $MySQL->query($consulta_itens);
                   while(list(
                              $PRODUTO_NOME,
                              $QUANTIDADE,
                              $PRECO_UNI,
                              $SEMI_TOTAL
                            ) = mysql_fetch_row($consulta_itens_query))
                {
                    $SUB_TOTAL+=$SEMI_TOTAL;

                    $texto.= "<tr>
                              <td align=\"left\" width=\"40%\">$PRODUTO_NOME</td>
                              <td align=\"center\" width=\"20%\">$QUANTIDADE</td>
                              <td align=\"right\" width=\"20%\">R$ ".number_format($PRECO_UNI, 2, '.', '')."</td>
                              <td align=\"right\" width=\"20%\">R$ ".number_format($SEMI_TOTAL, 2, '.', '')."</td>
                          </tr>
                       ";
                }
$texto.= "<tr><td align=\"center\" colspan=\"4\">Total do Cliente na data: R$ ".number_format($SUB_TOTAL, 2, '.', '')."</td></tr>";

$TOTAL_GERAL+=$SUB_TOTAL;
            }
$TOTAL_FORNECE+=$TOTAL_GERAL;            
$texto.=  "<tr><td align=\"center\" colspan=\"4\">Total do Fornecedor na data: R$ ".number_format($TOTAL_FORNECE, 2, '.', '')."</td></tr>";
   
     $texto.= "</table>";

    require_once("../global/funcoes_php/dompdf/dompdf_config.inc.php");
  
    $dompdf = new DOMPDF();
    $html = iconv("utf-8","iso-8859-1",$texto);
    $dompdf->load_html($html);
    $dompdf->set_paper('letter', 'landscape');
    $dompdf->render();
    $dompdf->stream("pdf/relatorio.pdf");
}
 ?>
</body>
</html>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...