Guides › mPDF › Output: show, download or save the PDF

Output: show, download or save the PDF

Written for mPDF 8.2 on PHP 8.1+. Updated 2 November 2026.

Output() finishes the document and sends it somewhere. It takes a file name and a destination:

use Mpdf\Output\Destination;

$mpdf->Output('report.pdf', Destination::INLINE);        // show in the browser
$mpdf->Output('report.pdf', Destination::DOWNLOAD);      // force a download
$mpdf->Output('/var/app/storage/report.pdf', Destination::FILE); // save on the server
$pdf = $mpdf->Output('', Destination::STRING_RETURN);   // return the bytes

The constants are the letters I, D, F and S, which you’ll still see in older code. Calling Output() with no arguments shows the PDF inline as doc.pdf.

Which one to use

  • INLINE for previews. The browser decides whether to show it or download it.
  • DOWNLOAD when the user clicked “Download invoice”. The file name you pass is the one they’ll see.
  • FILE to archive documents or generate them in a background job. The folder must exist and be writable by PHP.
  • STRING_RETURN whenever something else does the sending: attaching to an email, uploading to storage, or a framework response.

In a framework

Frameworks send their own headers, so return the bytes inside a response instead of letting mPDF echo them. In Laravel:

return response($mpdf->Output('', 'S'), 200, [
    'Content-Type' => 'application/pdf',
    'Content-Disposition' => 'inline; filename="invoice.pdf"',
]);

“Data has already been sent to output”

mPDF refuses to stream a PDF if anything has already been printed: an echo, a PHP notice, or even a blank line or byte-order mark before <?php. Remove the stray output (check display_errors too). Or, as a stopgap, call ob_clean() before Output(). The troubleshooting guide has more on this one.