Header and footer do not work on mpdf

Asked

Viewed 851 times

-1

I’m taking a look at mPHP to learn how to make reports with PHP, due to a case that occurred in my work, now I want to take care and learn how to use such tool, but I’m having problems(I tried to do similar to the work).

I can not put header and footer in the form, I tried several ways I saw on the internet, but nothing worked.

I wonder if someone could help me?

Each variable that I put here is in the same file, I will only separate to facilitate the visualization.

Code:

CSS:

$css="
    @page {
        margin-left: 20px;
        margin-right: 20px;
        margin-top: 15px;
        margin-bottom: 15px;
    }



    #cabecInicial{
        font-family: 'Century Gothic';
        color: #3864B2;
        background-image: url('imgs/cabecalho_relatorios_1_grande.png');
        background-position: right top;
        background-repeat: no-repeat;
        background-size: 70% 120%;
        background-color: #efefef;
        height: 160px;
        width: 100%;
    }

    #corpoCabecInicial{
        height: 115px;
        width: 100%;
        float: left;
        margin-top: 15px;
    }

    #dadosCabec {
        float: left;
        margin-left: 15px;
        width: 430px;
    }



    #corpoRelatCompleto{
        height: auto;//100%;//200px
        width: 100%;//1035    
        margin:0 auto;
    }

    .esquerdaEspaco10 {
        padding-left: 5px;
    }

    .subtitulo{
        font-weight: bolder;
        vertical-align: top;
    }

    .apertoDeMao{
        width: 154px;
    }


    .apertoDeMaoMini{
        float: left;
        width: 78px;
        margin: 8px;
    }

    #infoCabecInicial {
        vertical-align: bottom;
        font-size: 12px;

    }

    #obsCabec{
        opacity: 0.7;
        background: #144385;
        padding-left: 10px;
        padding-right: 5px;
        padding-top: 20px;
        padding-bottom: 20px;
        margin-left: 20px;
        margin-top: 5px;
        margin-right: 20px;
        width: 230px;
        height: auto;
        color: #fff;
        float: right;
        border-radius: 15px 15px 15px 15px;
        box-shadow: 3px -4px 3px 0px #336abd;
    }

    .textoFooter {
        margin-top: 20px;
        padding-right: 15px;
        float: right;
        color: #ffffff;
    }

    .footer {
        background: url('imgs/footerGambi.png');
        background-repeat: no-repeat;
        background-size: 100%;
        width: 100%;
        height: 50px;
        text-align: right;
        clear: both;
        //page-break-after:always;
        //position: fixed;
    }

    .basicHeader {
        background-image: url('imgs/cabecalho_relatorios_1.png');
        background-position: right top;
        background-repeat: no-repeat;
        background-size: 70% 180%;
        background-color: #efefef;
        width: 100%;
        height: 70px;
        clear: both
        font-size: 12px;
        float: left;
        position: fixed; top: 0px;//page-break-after:always;
    }

    .textoCabecGeral {
        float: left;
        font-size: 26px;
        color: #3864B2;
        width: 500px;
    }

    #corpoRelat {
        margin-top:65px;
        font-family: 'Tw Cen MT';
        font-size: 12.0pt;
    }

    .indice {    
        font-size: 22pt;
        border-bottom: 1px double;
        padding-bottom: 5px;
    }

    .numeroIndice {
        padding-right: 15px;
    }

    .subIndice {
        font-weight: bolder;
    }

    .tabelaSistema {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 35px;
    }

    .tabelaSistema td{
        border: 1px solid #000000;    
    }

    .tabelaSistema th{
        border: 1px solid #000000;    
    }

    .tabelaSistema .tdLess {
        width: 15%;
        text-align: center;
    }

    .tabelaSistema .first {
        text-align: left;
        padding-left: 15px;
    }

    #cabecTable {
        width: 100%;
    }

</style>"    

;

footer:

$footer = '

            <div class="footer">
                <div class="textoFooter">
                    ********
                </div>
            </div>

    ';

header:

$header = '

        <div class="basicHeader">
            <table>
                <tbody><tr>
                    <td><img src="./2016.07.12 relato_de_------.pdf_files/maoGambi.png" class="apertoDeMaoMini"></td><td>
                    </td><td><!-- textoCabecGeral-->
                        <div class="textoCabecGeral subtitulo">
                            RELATO DIÁRIO
                            <br>-------
                        </div>
                    </td><td>
                </td></tr>
            </tbody></table>


            </div>
        </div>

front page header:

$firstCabec = '

    <div id="cabecInicial">

        <div id="corpoCabecInicial">

                    <div style="height: 23px;"></div>

                        <div id="dadosCabec">
                            <table>
                                <tbody><tr>
                                    <td rowspan="2">
                                        <img src="./2016.07.12 relato_de_----.pdf_files/maoGambi.png" class="apertoDeMao">
                                    </td>
                                    <td class="subtitulo esquerdaEspaco10">
                                        RELATO DIÁRIO
                                        <br>Gerenciamento do ------------
                                    </td>
                                </tr>
                                <tr>
                                    <td id="infoCabecInicial" class="esquerdaEspaco10">
                                        #-------
                                        <br>08/08/2016
                                        <br>-------
                                    </td>
                                </tr>
                            </tbody></table>
                        </div>


                        <div id="obsCabec">
                            Principais ........ ++++++++ -----------.
                        </div>






        </div>

    </div>


';

body:

$corpo = '

    <div id="corpoRelatCompleto">


        texto totalmente aleatório gerado pelo Lorem Ipsum

    </div>




';

Joining together the HTML:

$pdfCompleto = $css.$inicioCorpo.$firstCabec.$corpo.$fimCorpo;

MPDF:

require_once ('mpdf60/mpdf.php'); 

$mpdf = new mPDF(); 
$mpdf->SetHTMLHeader($header, "E");
$mpdf->SetHTMLFooter($footer,"O");

$mpdf->charset_in='windows-1252'; 

$mpdf->WriteHTML($pdfCompleto);
$mpdf->Output();
  • Where found ur library mpdf60? check https://github.com/mpdf/mpdf is best to convertion

  • on the Official site: http://www.mpdf1.com/mpdf/index.php

  • Good afternoon, no need to write in English, we are on a site of the Portuguese language ;)

  • is why I was going to post in the 2 and ended up swapping with each other at the time of posting.

  • Yes this I realized, I’m referring to the comments, both yours and the Kingrider ;)

  • but getting back to the topic, you know you’ve had this problem, you know what might be happening?

  • @user3061516 never used mPDF, but it seems to me that the CSS of Header and Footer is not the same as the body (I may be wrong). I’ll test and run some tests.

Show 2 more comments

1 answer

0

I have the same problem. I was using PHP 5.6 and MPDF, all working perfectly. I upgraded my local server to PHP7 I did all the fixes and as amazing as it seems the only one I didn’t realize to solve is the issue of MPDF header and footer that are no longer displayed.

Follow my code that worked until the update:

$html= ob_get_contents();
ob_end_clean();
$dt = date("d/m/Y H:i");
$mpdf=new mPDF('c', 'A4'); 

$mpdf->SetDisplayMode('fullpage');
$mpdf->SetAuthor($_SESSION['nome']);
$mpdf->SetWatermarkText('- ID '.$_SESSION['id']);
$mpdf->showWatermarkText = true;
$mpdf->AddPage('P', // L - landscape, P - portrait
        '', 
        '', 
        '', 
        '',
        10, // margin_left
        10, // margin right
        15, // margin top
        45, // margin bottom
        5, // margin header
        15); //margin footer

 $footer = '<table border="0" width="800">
        <tr>
            <td width="400" align="center" valign="middle">QAP Questões - Conteúdo gerado de https:// - Impresso em: '.$dt.' - Pag. {PAGENO} de {nb}
            </td>

        </tr>
    </table>';

$cabecalho ="<div width=\"1000\">
<div style=\"font-size: 12px; font-family: arial\" align=\"right\"><b><i>Continuação do conteúdo gerado de https:// - Impresso em: ".$dt."</i></b><br><br>
 </div>";
$mpdf->SetHTMLHeader($cabecalho);
$mpdf->SetHTMLFooter($footer);
$mpdf->SetProtection(array('copy','print'), 'xxx', 'xxx');
$mpdf->WriteHTML($html);
$mpdf->Output($retorno['nome'].'.pdf', D);?>

Browser other questions tagged

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