【问题标题】:DOMPDF: files with 0 bytes and text/plain mime-typeDOMPDF:具有 0 字节和文本/纯 mime 类型的文件
【发布时间】:2010-06-22 14:38:51
【问题描述】:

我正在使用 Kohana 3 和 pdfview/DOMPDF 来生成 pdf 文件,但它们是用 0 字节和 text/plain mime-type 生成的。

控制器:

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

现在它正在工作。谢谢!

【问题讨论】:

  • 您是否按照安装说明进行操作?还可以尝试在编辑器中打开文件以查看实际内容。在将其分配为请求响应之前,您可以通过调用$pdfview-&gt;render() 来检查是否有错误。

标签: php mime-types kohana-3 dompdf filesize


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    当我更改文件夹 dompdf 的文件夹权限时,它似乎可以工作

    sudo chmod -rf 777 dompdf
    

    【讨论】:

      猜你喜欢
      • 2012-12-26
      • 1970-01-01
      • 2014-09-16
      • 1970-01-01
      • 2012-05-24
      • 2012-05-17
      • 2021-10-05
      • 2011-04-13
      • 1970-01-01
      相关资源
      最近更新 更多