2

I am generating multiple PDFs in a loop using mPDF. Following are the lines of my code:

for($i=0;$i<=3;$i++)
{
    $mpdf = new mPDF();
    $stylesheet = file_get_contents('style.css');

    $mpdf->WriteHTML($stylesheet,1);
    $mpdf->WriteHTML('My html');
    $mpdf->SetDisplayMode('fullpage');

    $pdfname="Invoice_No.$i".".pdf";
    $mpdf->Output($pdfname, "I");
}

When the change the parameter I to F multiple PDFs are generated on the server. However when using I as the parameter only first PDF is generated. Is there any way that I can generate multiple PDFs in such a way that I do not have to save them in the server?

Note: Even using parameter D does not help either

Draken
  • 3,134
  • 13
  • 34
  • 54
Sarah Mandana
  • 1,474
  • 17
  • 43

1 Answers1

3

TL;DR No, in one request, there is not.

I and D output modes generate the file, send the output from the server to the browser (inline and with forced download respectively) and end execution - so that no further data are sent that would corrupt sent PDF file.

You would have to execute multiple HTTP requests for each file.

Alternatively, you could save PDFs in-memory, later pack them eg to a ZIP file and send the ZIP file.

Finwe
  • 6,372
  • 2
  • 29
  • 44