mPDF Manual – mPDF functions



Output – Finalise the document and send it to specified destination


string 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.



The name of the file. If not specified, the document will be sent to the browser (destination I).

BLANK or omitted: “doc.pdf”


Destination where to send the document.

DEFAULT: “I” i.e. Browser

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.

D: send to the browser and force a file download with the name given by $filename.

F: save to a local file with the name given by $filename (may include a path).

S: return the document as a string. $filename is ignored.


Example #1


// Sends output inline to browser

$mpdf = new mPDF();

Hallo World



Example #2


// Saves file on the server as 'filename.pdf'

$mpdf = new mPDF();

Hallo World


Example #3 - Sending file as e-mail (and also to browser)

$mpdf = new mPDF();


$content = $mpdf->Output('', 'S');

$content = chunk_split(base64_encode($content));

$mailto = '';

$from_name = 'Your name';

$from_mail = '';

$replyto = '';

$uid = md5(uniqid(time()));

$subject = 'Your e-mail subject here';

$message = 'Your e-mail message here';

$filename = 'filename.pdf';

$header = "From: ".$from_name." <".$from_mail.">\r\n";

$header .= "Reply-To: ".$replyto."\r\n";

$header .= "MIME-Version: 1.0\r\n";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";

$header .= "This is a multi-part message in MIME format.\r\n";

$header .= "--".$uid."\r\n";

$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";

$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

$header .= $message."\r\n\r\n";

$header .= "--".$uid."\r\n";

$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";

$header .= "Content-Transfer-Encoding: base64\r\n";

$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";

$header .= $content."\r\n\r\n";

$header .= "--".$uid."--";

$is_sent = @mail($mailto, $subject, "", $header);