Output()
Output – Finalise the document and send it to specified destination
Note: As of mPDF v8.1.2 it is preferred to use verbose aliases
OutputBinaryData
,
OutputHttpInline
,
OutputHttpDownload
,
and OutputFile
Description
string|void Output ( [ string $filename [, string $dest ])
Send the document to a given destination: browser, file or string. In the case of browser, the plug-in may be used (if present) or a download (“Save as” dialog box) may be forced.
Parameters
- $filename
-
The name of the file. If not specified, the document will be sent to the browser (destination
\Mpdf\Output\Destination::INLINE
).BLANK or omitted:
'doc.pdf'
- $dest
-
Destination where to send the document. Use class constants from
\Mpdf\Output\Destination
for better readability and understandabilityDefault:
\Mpdf\Output\Destination::INLINE
- Values:
\Mpdf\Output\Destination::INLINE
, or"I"
- send the file inline to the browser. The plug-in is used if available.
The name given by $filename is used when one selects the “Save as” option on
the link generating the PDF. This parameter sets HTTP headers using standard
header
PHP function. \Mpdf\Output\Destination::DOWNLOAD
, or"D"
- send to the browser and force a file download with the name given by
$filename. This parameter sets HTTP headers using standard
header
PHP function. \Mpdf\Output\Destination::FILE
, or"F"
- save to a local file with the name given by $filename (may include a path).
\Mpdf\Output\Destination::STRING_RETURN
, or"S"
- return the document as a string. $filename is ignored.
Note: You can use the \Mpdf\Output\Destination::STRING_RETURN
option to e-mail a PDF file - see example under
E-mail a PDF file.
Examples
Example #1
<?php
// Sends output inline to browser
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('Hello World');
$mpdf->Output();
Example #2
<?php
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('Hello World');
// Saves file on the server as 'filename.pdf'
$mpdf->Output('filename.pdf', \Mpdf\Output\Destination::FILE);