Serve PDF file with PHP

// pdfString is the *contents* of a file.
// to serve a file that exists on the file system, use readfile() instead of print $pdfString

header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($pdfString));
header('Content-Disposition: attachment; filename=' . 'pdf_dynamic.pdf');
ob_clean();
flush();
print $pdfString;
exit;

source

Comments are closed.