Search code examples
phpmemorypdf-generationdompdfmemory-limit

Create PDF file with BIG html CODE


I have to generate PDF document from big HTML code (created 1000 or more pages). But standard method limited me - memory. Standard method:

$html = generatePDF($data_to_pdf);
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper('a4', 'landscape');
$dompdf->render();
$pdf = $dompdf->output();

file_put_contents('pdf/' . $tmp_name . '.pdf', $pdf);

The memory is too small so I need to save the data in part. How to generate PDF page by page? Or something like that? How to fix memory problem?


Solution

  • Try taking a look at this: https://pdfmerger.codeplex.com/

    Then, divide the html, render each part into a separate file, and then merge them afterwards..