Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default filename when using mPDF

Tags:

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.

like image 498
Jason Avatar asked Jan 08 '16 22:01

Jason


People also ask

How do I change my title in mPDF?

you can used $pdf->SetTitle('My Doc'); . But Set the title for the document. The title is displayed at the top of the Adobe Reader screen when viewing the PDF file, and is include in the document metadata, which can be seen when inspecting the document properties in Adobe Reader.

What is mPDF file?

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

How do I add a page in mPDF?

If writing a DOUBLE-SIDED document, a conditional page-break ( $type = "E" or "O" ) will add a new page only if required to make the current page match the type (i.e. ODD or EVEN); a page-break with $type = "NEXT-ODD" or "NEXT-EVEN" will add one or two pages as required to make the current page match the type (i.e. ODD ...


1 Answers

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');
like image 74
Trolley Avatar answered Oct 18 '22 18:10

Trolley