Question

I am using mpdf library to generate pdf from html(table) content in php. I am using below code

<?php 
    session_start();
    $html=$_POST['html'];
    include 'mpdf.php';
    $mpdf=new mPDF(); 
    $mpdf->WriteHTML($html);
    $mpdf->Output();
    exit;
    ?>

When the size of html table is small, say about 100 rows, then PDF is generated properly. But when size of table is more, say about 1000-2000 rows, then pdf is not generated.

Is there any size constraint in mpdf? What can be done to solve this problem? Or is there any other better library to generate pdf's in php

I have tried increasing memory allocated to 256,512 and 1024 mb in php.ini by using this code ini_set('memory_limit', '256M'); I also tried increasing time limit, it is now generating PDF but taking more time to generate and PC becomes slow. How can I release memory?

Was it helpful?

Solution

Try

ini_set('max_execution_time', 0);
ini_set("memory_limit", "2G");

$mpdf->packTableData = true;

And as usual, be wary of bad nesting, unclosed tags, improper escaping, or wrong colspan settings. Check generated HTML code with http://validator.w3.org/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top