DOMPDF:具有 0 字节和文本/纯 mime 类型的文件

发布于 2024-09-06 10:56:59 字数 1989 浏览 7 评论 0原文

我正在使用 Kohana 3 和 pdfview/DOMPDF 生成 pdf 文件,但它们是使用 0 字节和文本/纯 mime 类型生成的。

控制器:

public function action_pdf() {
    if(isset($_POST['dados'])) {
        $pdf = View_PDF::factory('export/pdf');
        $pdf->title = '';
        $pdf->headers = array();
        $pdf->data = array();

        $this->request->response = $pdf;
        $this->request->send_file(true, 'dados.pdf');
    }
}

视图:

<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <style type="text/css">
        * {
            border: 0;
            margin: 0;
            padding: 0;
        }

        table {
            border: 1px solid;
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
            width: 500px;
        }

        td {
            border: 1px solid;
            padding: 5px;
        }
        </style>
    </head>
    <body>
        <h1>Teste</h1>
        <table>
            <tr></tr>
        </table>
    </body>
</html>

当我下载文件并在 epdfview(PDF 查看器)中打开它时,它说:

Unable to open document
File type plain text document (text/plain) is not supported

我只是不知道出了什么问题。谢谢。

更新:

我下载了 DOMPDF 的最新测试版,删除了 pdfview Kohana 模块,并在我的控制器中执行了类似的操作:

public function action_pdf() {
        if(isset($_POST['dados'])) {
            require_once(Kohana::find_file('vendor', 'dompdf/dompdf_config.inc'));

            $view = View::factory('report/pdf');
            $view->title = '';
            $view->data = array();

            $pdf = new DOMPDF();

            $pdf->load_html($view->render());
            $pdf->render();
            $pdf->stream('dados.pdf', array('Attachment' => 1));
        }
    }

现在它可以工作了。谢谢!

I'm using Kohana 3 and pdfview/DOMPDF to generate pdf files but they are generated with 0 bytes and text/plain mime-type.

Controller:

public function action_pdf() {
    if(isset($_POST['dados'])) {
        $pdf = View_PDF::factory('export/pdf');
        $pdf->title = '';
        $pdf->headers = array();
        $pdf->data = array();

        $this->request->response = $pdf;
        $this->request->send_file(true, 'dados.pdf');
    }
}

View:

<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <style type="text/css">
        * {
            border: 0;
            margin: 0;
            padding: 0;
        }

        table {
            border: 1px solid;
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
            width: 500px;
        }

        td {
            border: 1px solid;
            padding: 5px;
        }
        </style>
    </head>
    <body>
        <h1>Teste</h1>
        <table>
            <tr></tr>
        </table>
    </body>
</html>

When I download the file and open it in epdfview (PDF viewer), it says:

Unable to open document
File type plain text document (text/plain) is not supported

I just don't know what's wrong. Thank you.

UPDATE:

I downloaded the last beta version and of DOMPDF, deleted the pdfview Kohana's module and did something like that in my controller:

public function action_pdf() {
        if(isset($_POST['dados'])) {
            require_once(Kohana::find_file('vendor', 'dompdf/dompdf_config.inc'));

            $view = View::factory('report/pdf');
            $view->title = '';
            $view->data = array();

            $pdf = new DOMPDF();

            $pdf->load_html($view->render());
            $pdf->render();
            $pdf->stream('dados.pdf', array('Attachment' => 1));
        }
    }

Now it's working. Thanks!

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

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

发布评论

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

评论(2

野心澎湃 2024-09-13 10:56:59

我遇到了类似的问题,并收到此“不支持 dompdf 文件类型纯文本文档(文本/纯文本)”消息。我检查了安装说明,它与更改 dompdf 目录上的文件/文件夹权限有关(lib/fonts 是安装说明中特别提到的内容)。现在可以工作了。

I ran into a similar issue, and got this "dompdf File type plain text document (text/plain) is not supported" message. I checked out the install directions, and it had to do with changing file/folder permissions on the dompdf directory (lib/fonts is what was specifically mentioned in the install instructions). Works now.

雨夜星沙 2024-09-13 10:56:59

当我更改文件夹 dompdf 的文件夹权限时,这似乎有效

sudo chmod -rf 777 dompdf

It seems to be work When I changed the folder permission of folder dompdf

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