D
D
Dmytro Karpovych2015-07-10 16:02:13
PHP
Dmytro Karpovych, 2015-07-10 16:02:13

Why doesn't a file from mPDF open in Chrome?

Good afternoon.
I generate a pdf file via mPDF (v6.0):

$file = 'file.pdf';
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/octet-stream");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Accept-Ranges: bytes');
header("Content-Disposition:inline;filename='$file");

include 'vendor/autoload.php';
ob_start();
require 'pdf-template.php';
$html = utf8_encode(ob_get_contents());
$css = file_get_contents('css/all.css') . PHP_EOL . file_get_contents('css/pdf.css');
$mpdf = new mPDF('utf-8', 'A4', '8', '', 10, 10, 7, 7, 10, 10);
$mpdf->list_indent_first_level = 0;
$mpdf->WriteHTML($css, 1);
$mpdf->WriteHTML($html);
$mpdf->Output($file, 'D');
exit;

After downloading, the file does not open in Chrome, but the reader opens normally. Chrome writes: "Failed to load PDF document".
Tell me, please, what to do.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitryim, 2015-07-26
@dmitryim

I recommend opening the resulting file in a text editor and making sure that there is nothing superfluous in it (excessive spaces at the beginning, PHP errors and other garbage).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question