2
I have the following code in my application to generate a PDF report:
$head = '<html><head>'
. '<title>Relatório</title><style type="text/css">'
. '@page {margin: 120px 50px 80px 50px;}.head{font-size: 12px;height: 100px;width: 100%;position: fixed;top: -90px;left: 0;right: 0;margin: auto;}.main-content{width: 600px;position: relative;margin: auto;}.footer {font-size: 12px;position: fixed;bottom: 0;width: 100%;text-align: right;}#footer .page:after{content: counter(page); }'
. '</style></head><body>';
$header = '<div class="head">Cabeçalho</div>';
$footer = '<div class="footer">Rodapé</div>';
$content = '<div class="main-content">'
. '<h1 class="text-center">Relatório</h1>'
. 'Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />Conteúdo<br /><br /><br />'
. '</div>';
$html = $head.$header.$content.$footer;
$pdf = \PDF::loadHTML($html);
return $pdf->stream();
I made it based on that reply, but I don’t know why the footer doesn’t appear on the first page, only on the second. The header appears correctly on all.
I’m using Laravel 5.1 with the Laravel-dompdf.
Use ID instead of CLASS to see if it works.
– Diego Souza
error: Domnode::cloneNode(): ID head already defined
– Raylan Soares
But it’s just to put ID in Header and Footer. Sorry.
– Diego Souza
still error, where I leave this error ID. and if I put class it does not put the footer in the first.
– Raylan Soares
if there is at least a way to remove the header from the first page too
– Raylan Soares