Changing the default filename when using mPDF

做~自己de王妃 提交于 2019-12-09 02:47:15

问题


I'm currently using mPDF to generate a pdf from HTML (which was generated by PHP).

All works as expected but I'd like to be able to change the default filename. Currently, I have:

$payStub=new mPDF();
$payStub->SetTitle('My title');
$payStub->WriteHTML($pcTableRows);
$payStub->Output();

When I save the pdf that opened in my browser it defaults to mpdf.pdf.
Is it possible to change mpdf.pdf to something of my choosing?

I tried

$payStub->Output('myFileName.pdf');

and

$payStub->Output('myFileName.pdf', 'F');

but those want to save it to the server, I'm trying to have it for when the user saves it locally.


回答1:


Try the I flag in the Output function, which will output the PDF to the browser, and use the filename from the first argument:

$payStub=new mPDF();
$payStub->SetTitle('My title');
$payStub->WriteHTML($pcTableRows);
$payStub->Output('yourFileName.pdf', 'I');



回答2:


You can try as:

$file_name = 'yourFileName.pdf';
$mpdf->Output($file_name, 'D');

Help:

  1. 'D': download the PDF file
  2. 'I': serves in-line to the browser
  3. 'S': returns the PDF document as a string
  4. 'F': save as file $file_out



回答3:


Modify mdpdf.php

form.setAttribute("action", "'._MPDF_URI.'includes/out.php/'.$name.'");

for downloading with other name



来源:https://stackoverflow.com/questions/34687293/changing-the-default-filename-when-using-mpdf

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