MPDF文件仅在浏览器中起作用,而不是在Adobe Acrobat中(格式错误)

发布于 2025-02-10 07:06:09 字数 1758 浏览 2 评论 0原文

我使用此代码创建一个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无法打开由不受支持的Filetype或损坏/损坏的文件引起的文件。

因此,我介绍了不同的标头选项,但是在每种情况下,我都会有相同的结果。

我如何使用MPDF创建一个PDF文件,该文件由Adobe Acrobat支持与它们一起打开?

关注这篇文章(如何制作mpdf 6.1使用PHP 7.1.5 ),无法解决问题。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-02-17 07:06:09

最后,问题很容易解决。

因此,我在编码/文本编辑器中打开PDF文件。

在那里,我可以看到一些php-errors/错误打击。

在mpdf.php中,我更改了$ errorLevel = error_reporting(e_error | e_parse);

全部。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文