Home > Software design >  mpdf file only works in browser, not in adobe acrobat (format error)
mpdf file only works in browser, not in adobe acrobat (format error)

Time:07-01

I create a pdf file with this code.

case 'D':
//Download file
        header('Content-Description: File Transfer');
        if (headers_sent())
            $this->Error('Some data has already been output to browser, can\'t send PDF file');

            //Time on timezone summertime
            if(date('I',filemtime ($name))==1){ $timez=filemtime ($name) 3*3600;}else{ $timez=filemtime ($name) 2*3600;}
            
            header('Pragma: public');   // required
            header('Expires: 0');       // no cache
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Cache-Control: private',false);
            header('Last-Modified: '.gmdate ('D, d M Y H:i:s', $timez).' GMT');
            
            
            //header('Content-Type: '.'application/pdf');
            //header('Content-Type: application/pdf');
            
            header('Content-Type: application/force-download');
            //header('Content-Type: application/octet-stream', false);
            //header('Content-Type: application/download', false);
            //header('Content-Type: application/pdf', false);

            header('Content-Disposition: attachment; filename="'.$name.'.pdf"');
            header('Content-Transfer-Encoding: binary');

            header('Connection: close');

The PDF file will create successful. If I open the created file in my browser, all is ok. If I click in my explorer and try to open with adobe acrobat, I get a error-message that adobe could not open the file caused by unsupported filetype or damaged/corrupt file.

So I play a bit about the different header options, but in every case at the end I have the same result.

How I can create a pdf file with mpdf which is supported by adobe acrobat to open it with them?

Follow this post(How to make mPDF 6.1 work with PHP 7.1.5), won't fix the problem.

Thanks

CodePudding user response:

At the end the problem was easy to fix.

So i open the pdf-file in my coding/text-editor.

There i could see some php-errors/error-warnings.

In the mpdf.php i changed the $errorlevel=error_reporting(E_ERROR | E_PARSE);

thats all.

  • Related