Search code examples
laravelmpdf

MPDF - Laravel , multi footer


I am using : https://github.com/mccarlosen/laravel-mpdf/issues to generate pdf , all ok except when i use multi footer , now the footer show only on page 1 (MyFooter1) and 2 (MyFooter2).

I need to show staring page2 on all pages (MyFooter2) .I am finding the correct syntax , below my code I used <sethtmlpagefooter name="MyFooter2" page="ON" value="1" write="true" /> to show the footer , it show only the footer only on the page where it exist .

 <!DOCTYPE html>
    <html>
    <head>
        <title>My title</title>
    </head>
    @include('pdf.css2')
    <body>
    
    
        <htmlpagefooter name="MyFooter1" style="display:none">
            <div class="print-footer">
                <div class="footer-section-1" >
                    <div style="width:20% ; float:left; padding-right: 5px;">
    
                      My company name
                    </div>
                    <div style="width:20%  ;float:left; padding-right: 5px;">
                        <div> <b>T</b><span> : +98 123 123</span></div>
                        <div>  <b>T/F</b><span>: +98 123 123</span></div>
                        <div>  <b>Email</b><span>: [email protected]</span></div>
                    </div>
                    <div style="width:35% ; float:left; padding-right: 5px;">
                        <div>  <b>Head Office</b></div>
                        <div> <span>test test,</span> </div>
                        <div> <span>Road, test, </span></div>
                         <div> <span>  USA</span></div>
                        <div> <span>P.O. Box 211265 </span></div>
    
                    </div>
                    <div style="width:11% ; float:left; padding-right: 5px;">
                        <div><b>Branches</b></div>
                        <div><span>B1</span></div>
                        <div><span>B2</span></div>
    
                    </div>
                    <div style=" float:left; padding-right: 20px;padding-top: 20px;">
                       WE ARE THE BEST
                    </div>
                </div>
               
            </div>
        </htmlpagefooter>
    
    
        <htmlpagefooter name="MyFooter2" style="display:none">
            <div class="print-footer">
               My company name
            </div>
        </htmlpagefooter>
    
    
    
    
        <div class="page1" >
            <div style=" text-align: center ;"  >
                <div class="logo">
                    @include('pdf.company logo')
                </div>
                <div class="title" >
                    <span class="span-title"  > <b>INDIVIDUAL  OFFER </b>  </span>
                    <div class="div-name" ><span class="span-name" >client </span></div>
                    <div>
                        <div class="info" style="width:50% ;float:left; padding-right: 5px;">DATE: December 2, 2020</div>
                        <div class="info" style="float:right; padding-right: 5px;">REFERENCE NUMBER: vd 123 xl</div>
                    </div>
                </div>
            </div>
            <div class="message">
                <p >
                    Dear Ms. ,
                </p>
                <p>
                    We believe that the following offer is the first step to a long and happy relationship between us.            </p>
                <p>
                    Allow us to put your worries aside with our special  programs.
                </p>
                <p>
                    Best Regards,
                </p>
            </div>
        </div>
        <sethtmlpagefooter name="MyFooter1" value="1" />
    
        <div class="chapter2">
            <div class="message">
                 <p >
                    Dear Ms. ,
                </p>
                <p>
                    We believe that the following offer is the first step to a long and happy relationship between us.            </p>
                <p>
                    Allow us to put your worries aside with our special  programs.
                </p>
                <p>
                    Best Regards,
                </p>
            </div>
        </div>
        <sethtmlpagefooter name="MyFooter2" page="ON" value="1" write="true" />
        <div class="chapter2">
            <div class="message">
                <p >
                    Dear Ms. ,
                </p>
                <p>
                    We believe that the following offer is the first step to a long and happy relationship between us.            </p>
                <p>
                    Allow us to put your worries aside with our special  programs.
                </p>
                <p>
                    Best Regards,
                </p>
            </div>
        </div>
        <div class="chapter2">
            <div class="message">
                <p >
                    Dear Ms. ,
                </p>
                <p>
                    We believe that the following offer is the first step to a long and happy relationship between us.            </p>
                <p>
                    Allow us to put your worries aside with our special  programs.
                </p>
                <p>
                    Best Regards,
                </p>
            </div>
        </div>
        <div class="chapter2">
            <div class="message">
                <p >
                    Dear Ms. ,
                </p>
                <p>
                    We believe that the following offer is the first step to a long and happy relationship between us.            </p>
                <p>
                    Allow us to put your worries aside with our special  programs.
                </p>
                <p>
                    Best Regards,
                </p>
            </div>
        </div>
  
    </body>
    </html>

Solution

  • in CSS , I used this :

     @page  {
    
            footer: html_MyFooter2;
            margin-bottom: 170px;
        }
    
            @page :first {
                footer: html_MyFooter1;
    
        }
    

    and in HTML I removed :

     <sethtmlpagefooter name="MyFooter1" value="1" />
     <sethtmlpagefooter name="MyFooter2" value="1" />
    

    This fix the issue and help me , refer to : Mpdf different header for first page 3rd answer (by : Ningappa )