I use mpdf to create PDF files on the fly and the files open in a browser, but Adobe gives me an error:
Adobe Acrobat Reader DC was unable to open 'example-filename.pdf' because it is either an unsupported file type or because the file (for example, it was sent as an email application and was incorrectly decoded).
I examined other questions about this ( another mpdf + adobe error ) and checked the pdf in a text editor. I found that the first part of the file looked like this:
<!DOCTYPE html>
<head>
<title>
CapstoneDB
</title>
%PDF-1.4
%âãÏÓ
After I deleted everything before %PDF-1.4
(including the tab), the file was perfectly open in Adobe, and this is great, except that I need to get open pdf files to open in Adobe without manually launching it using the code every time.
Here is my wrapper function that calls mpdf with html and css:
include('../mpdf/mpdf.php');
function user_download_pdf($html, $css_file, $filename) {
$mpdf = new mPDF();
$stylesheet = file_get_contents($css_file);
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output($filename, "D");
}
I never download a mpdf full html page, usually only h3 and one or more tables. Perhaps I need to provide mpdf with the whole html page, including <head>
, <body>
etc.? Is there a way to change the mpdf configuration or the way I call mpdf in php that will get rid of the html garbage at the beginning of the pdf file that unloads everything?
source
share