6
Is there any way to set up DOMPDF to put a header on all pages of the generated PDF?
I am generating a report and I would like all pages of the report to have the header of the first.
//define o estilo da página pdf
$style='
<style>
@page {
margin-top: 20px;
}
#head{
background-image: url("fad.jpg");
background-repeat: no-repeat;
font-size: 25px;
text-align: center;
height: 60px;
width: 500px;
margin: 0 auto;
}
#corpo{
width: 500px;
margin: 0 auto;
}
table{
border-collapse: collapse;
}
td{
padding: 3px;
}
</style>';
//define o cabeçalho da página
$head='<div id="head">Lista de Compras</div>
<div id="corpo">';
//inclui a biblioteca do dompdf
require_once("lib/dompdf/dompdf_config.inc.php");
//recebendo os dados do Formulário
$quant=$_POST['quantidade'];
$tipo=$_POST['tipo'];
$produto=$_POST['produto'];
$obs=$_POST['obs'];
//define o corpo do documento
$body='
<table border="1px" >
<tr bgcolor="#ccc">
<td>Quantidade</td>
<td>Tipo</td>
<td>Produto</td>
<td>Obs.</td>
</tr>
';
for ($i = 0; $i < count($quant); $i++) {
$tmp='<tr>
<td width="15%">'.$quant[$i].'</td>
<td width="15%">'.$tipo[$i].'</td>
<td width="40%">'.$produto[$i].'</td>
<td width="30%"> '.$obs[$i].'</td>
';
$body=$body.$tmp;
}
//define o rodapé da página
$footer='
</table>
</div>
';
//concatenando as variáveis
$html=$head.$style.$body.$footer;
//gerando o pdf
$html = utf8_decode($html);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("compras.pdf");
How is your HTML ?
– Diego Souza
@Diegosouza, I edited the question and put the full code
– Amanda Lima
Right. In your
#head
, putsposition:fixed
and forehead.– Diego Souza
@Diegosouza, it didn’t work.
– Amanda Lima
Is it not your cache ?
– Diego Souza
No, I already checked that
– Amanda Lima
With the
position:fixed
place a position.top: 10px; left: 0; right: 0; margin: auto;
.– Diego Souza
Hasn’t worked yet :/
– Amanda Lima
But let’s do it right... Equal in the same HTML.
<html><head><style></style></head><body></body></html>
. I mean, put on the Tagashtml
andhead
and withinhead
puts thestyle
, maintains theposition:fixed
in the#head
.– Diego Souza
@Diegosouza, I did everything right and it still didn’t work.
– Amanda Lima
I will simulate on my localhost.
– Diego Souza