Unable to generate multiple PDFs using mPDF when I do not want to download files on server

末鹿安然 提交于 2019-12-23 04:08:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!