codeigniter mpdf文件只能在浏览器中工作,不能在adobe acrobat中(格式错误)

dphi5xsq  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(119)

我用这个代码创建一个pdf文件。

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');

PDF文件将成功创建。如果我在浏览器中打开创建的文件,一切正常。如果我在浏览器中单击并尝试使用Adobe Acrobat打开,我会收到一个错误消息,说明Adobe无法打开文件,原因是不支持的文件类型或损坏的文件。
所以我玩了一点关于不同的标题选项,但在每一种情况下,在最后我有相同的结果。
我如何创建一个PDF文件与mpdf这是由adobe acrobat支持打开它与他们?
关注这篇文章(How to make mPDF 6.1 work with PHP 7.1.5),不会解决这个问题。
谢谢

e0bqpujr

e0bqpujr1#

最后这个问题很容易解决。
因此,我在我的编码/文本编辑器中打开pdf文件。
在那里我可以看到一些PHP错误/错误警告。
在mpdf.php中,我更改了$errorlevel=error_reporting(E_ERROR | E_PARSE);
就这样。

相关问题