问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/37719545/unable-to-generate-multiple-pdfs-using-mpdf-when-i-do-not-want-to-download-files