PDF does not generate all pages with mPDF

Asked

Viewed 1,016 times

0

I have a query that returns me 8,093 records both in the database and in a PHP system. I’m making a report using mPDF that regardless of the filter, it only generates 6 pages, which in my opinion, rules out the possibility of picking up any null or unformatted data. My report has header and footer and is printing 25 lines per page.

    <?php 
    include 'MPDF57/mpdf.php'; 
 include 'conect/conecta.php';
 include 'banco-os.php';
 include 'logica-usuario.php';

 $OSid              = $_POST['OSid'];
 $dataHora          = $_POST['dataHora'];
 $NomeEquipamento   = $_POST['NomeEquipamento'];
 $NomeSetor         = $_POST['NomeSetor'];
 $motivoOs          = $_POST['motivoOs'];
 $TotalMaterial     = $_POST['TotalMaterial'];
 $NomeTipoOS        = $_POST['NomeTipoOS'];
 $status            = $_POST['status'];

 $topo = "

    <table border='1' class='table table-striped'  style='font-size: 12px;' >
        <tr>
            <td colspan='1' width='10%'><img src='imagens/logo-mini.png' class='img-responsive img-rounded'></td>
            <td colspan='7' width='90%' class='textCenter'>
                <p>            
                    Av. Lobo Júnior, 688 - Penha Circular - Rio de Janeiro - RJ<br>CEP: 21020-125
                    Telefones: 2156-0500<br > Assistência Técnica: 2156-0525 <br>
                    E-mail: <a href='mailto:[email protected]'>[email protected]</a> - Site: <a href='www.riomed.com.br'>www.riomed.com.br</a>                
                </p>
            </td>            
        </tr>        
    </table>";

 $corpo_pagina = "
<!DOCTYPE html>
<html lang='pt-br'>
<head>
    <meta charset='UTF-8'>
    <title>Relatório - RioMed</title>
    <link href='css/bootstrap.css'  rel='stylesheet'>
    <style media='print'>
        body {
            font-family: sans-serif;
            }
    a {
        color: #000066;
        text-decoration: none;
    }
    table {
        border-collapse: collapse;
    }
    thead {
        vertical-align: bottom;
        text-align: center;
        font-weight: bold;
    }

    tfoot {
        text-align: center;
        font-weight: bold;
    }
    th {
        text-align: left;
        padding-left: 0.35em;
        padding-right: 0.35em;
        padding-top: 0.35em;
        padding-bottom: 0.35em;
        vertical-align: top;
    }
    td {
        padding-left: 0.35em;
        padding-right: 0.35em;
        padding-top: 0.35em;
        padding-bottom: 0.35em;
        vertical-align: top;
    }
    .textCenter{
        text-align: center;
        }

    img {
        margin: 0.2em;
        vertical-align: middle;
    }
    table.print-friendly tr td, table.print-friendly tr th {
        page-break-inside: avoid;
    }
    </style>

</head>
<body>


    <table border='1' class='table table-striped'  style='font-size: 12px;'  >
        <thead> 
            <tr>
                <th width='6%'>COD OS</th>
                <th width='8%'>DATA</th>   
                <th>SETOR</th>  
                <th>EQUIPAMENTO</th>            

                <th width='12%'>CUSTO TOTAL</th>
                <th>TIPO OS</th>
                <th width='17%'>STATUS</th>
            </tr>
        </thead>";
            for($i = 0; $i < count($OSid); $i++){   
                $corpo_pagina .="
        <tr>
            <td>".$OSid[$i]."</td>
            <td>".$dataHora[$i]."</td>
            <td>".$NomeSetor[$i]."</td>    
            <td>".$NomeEquipamento[$i]."</td>            
            <td>".$TotalMaterial[$i]."</td>
            <td>".$NomeTipoOS[$i]."</td>
            <td>".$status[$i]."</td>
        </tr>
        ";                
        }

$corpo_pagina .= "</table>";

 $rodape = "

<table width='100%' style='vertical-align: bottom; font-family: serif; font-size: 8pt; color: #000000; font-weight: bold; font-style: italic;'>

<tr>
        <td width='33%'><span style='font-weight: bold; font-style: italic;'>{DATE d/m/Y}</span></td>
        <td width='33%' align='center' style='font-weight: bold; font-style: italic;'>{PAGENO}/{nbpg}</td>
        <td width='33%' style='text-align: right; '>Rio Med</td>
    </tr>
</table>
</body>
</html>

 ";

 date_default_timezone_set('America/Sao_Paulo');
    $date = date('d/m/Y H:i');

    $arquivo = $date." - Relatorio.pdf";

    $mpdf = new mPDF('utf-8', 'A4-L',7,'MS Serif',7,7,27,13);    



    $mpdf->SetDisplayMode('fullpage');

    $mpdf->SetHTMLHeader($topo,'0',true);

    $mpdf->SetHTMLFooter($rodape);

    $mpdf->AddPageByArray(array(

    'orientation' => 'L',

    'mgl' => '10',

    'mgr' => '10',

    'mgt' => '30',

    'mgb' => '20',

    'mgh' => '10',

    'mgf' => '10',

    ));


    $mpdf->writeHTML($corpo_pagina);

    $mpdf->Output($arquivo, 'I');
    exit();
  • has come to check memory and disk space issues? Some processes may be interrupted in these situations. As for mPDF, I always preferred TCPDF because it is available in packagist

  • Knew q the post has limit. I do not know if it can increase. 8gb ram memory without locking and hd should have some 800gb Libres. i5.

  • 1

    now that I realized that all data comes by POST. That’s right, there is a directive called post_max_size that sets the maximum post size in MB. Another directive is max_input_vars that defines how many variables can be inserted in a query string, whether get or post. You should change them.

  • 1

    Another point, in the case of memories, the PC is one thing, the memory that PHP uses is defined by directives in the php.ini, in this case, if the above changes do not work, try checking on the memory in use.

  • It didn’t work. http://imgur.com/a/w7Zk9 Nothing has changed. You know what can be?

  • http://imgur.com/a/EoeqO Look at the result of my report. Whatever information is presented in the report, always in the same place.

  • what were the modifications you made? Restarted apache as amended?

  • ; How Many GET/POST/COOKIE input variables may be accepted ; max_input_vars = 1000 Para ; How Many GET/POST/COOKIE input variables may be accepted max_input_vars = 1000 E essa ; http://php.net/post-max-size post_max_size=32M

  • 1

    Your max_input_vars remains the same, increase to 10000 and test.

  • It worked. But I had to increase the timeout from 30 to 3000. Only there the answer so I can score.

  • Now it’s only going up to 58 pages. I made a query of 8,083 records and this should return me 323 pages. There is no need to print such a report. Then I will make improvement to pass only the parameter via post and generate the report straight from the database. Thanks.

  • I got it. I put max_input_vars for 9000 and post_max_size =128M Thanks.

  • Answer your own question. It is better if people know that you have solved the problem, and how you solved the problem.

  • @Gabrielheming Fabor put his solution as answer to finalize this question. Solved by increasing the memory of the post.

  • 1

    Good morning, what helped me was to increase Pcre.backtrack_limit = 100000 to 9000000. In php.ini Valew

Show 10 more comments

1 answer

0


Since you are sending various data through a form using the POST request method, and as discussed in the comments, you need to configure the following directives in php.ini:

  • post_max_size;
  • max_input_vars;
  • max_execution_time.

post_max_size indicates the maximum size that can be used for data sent by POST. If you pass this size, the excess data is ignored. Default 8M, increase to 128. https://secure.php.net/manual/en/ini.core.php#ini.post-max-size

max_input_vars indicates the maximum amount of variables that can be sent from the client to the server (either GET, POST or COOKIES). Default 1000, increase to 10000. https://secure.php.net/manual/en/info.configuration.php#ini.max-input-vars

The moment you increased the directives post_max_size and max_input_vars, your script started to take longer to run (you have more variables for the report). This way, your script can start presenting timeout.

max_execution_time sets the maximum time a PHP script can run. Scripts like reports can take longer than the normal page query. Default 30, increase as much as necessary. If time is varied, you can include 0 to be treated as "no limit". https://secure.php.net/manual/en/info.configuration.php#ini.max-Execution-time

Browser other questions tagged

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