L
L
leni_m2017-08-04 15:32:18
PHP
leni_m, 2017-08-04 15:32:18

How to properly use the mpdf library in php (chrome bug)?

Here is the code that generates the pdf and opens it in the browser:

header("Content-Type: application/pdf");
            header("Content-Disposition:inline;filename=\"invoice.pdf\"");
            header("Content-Transfer-Encoding: binary");

            ob_start();
            include 'file.php';
            $html = ob_get_contents();
            ob_end_clean();

            include("mpdf60/mpdf.php");

            $mpdf = new mPDF('utf-8', 'A4', '12', '', 10, 10, 7, 7, 10, 10);

            $stylesheet = file_get_contents('css/invoice.css'); //подключаем css
            $mpdf->WriteHTML($stylesheet, 1);

            $mpdf->WriteHTML($html, 2); //формируем pdf
            $mpdf->Output('file.pdf', 'I');

Everything is fine in the mazil, but in chrome it says "Failed to load pdf document" with the "Reload" button, which you click on, the page is updated and everything is fine.
How to get rid of this error, and so that the pdf is loaded immediately?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question