Footer does not appear on the first page - Laravel Dompdf

Asked

Viewed 833 times

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.

  • error: Domnode::cloneNode(): ID head already defined

  • But it’s just to put ID in Header and Footer. Sorry.

  • still error, where I leave this error ID. and if I put class it does not put the footer in the first.

  • if there is at least a way to remove the header from the first page too

2 answers

0

Try adding the content inside the main-content, so it will not be totally left and will be more visible, besides in the footer it is good to put the z-index since it is fixed.

<div class="footer"><div class="main-content">Rodapé</div></div>


<style>
    .footer {
    font-size: 12px;
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: right;
    z-index: 1;
}
</style>

-1

See if it works.

<?php

$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> </body></html>';

$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();
  • If it doesn’t work, you need to use classes anyway. I’ve never used this library for Laravel.

  • Unfortunately I continue with the error Domnode::cloneNode(): ID head already defined

  • because it is the question with classes of this bug of not loading the footer on the first page, tense...

  • Copy my code and run it there. I updated it.

  • now the footer does not appear on any page rs

  • Ah Mano... Wait a minute.

  • I updated the code. Run now.

  • We’re back to square one, page one without the footer. I’ve reviewed it a thousand times and I can’t find anything wrong... to almost consider searching a new way to generate PDF pq can be a bug in this domPDF that I’m using.

  • That may be so. On the topic you quoted that I helped the girl there was that too.

  • Yeah, I’ll search another one here, in case I get Aki post later. Anyway thanks @Zoom

  • I will give -1 because kick is not problem solving proposal.

  • @Thank you zézão dvd from Asp.

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.