问题
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:
- 'D': download the PDF file
- 'I': serves in-line to the browser
- 'S': returns the PDF document as a string
- '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