开发者

DOMPDF: files with 0 bytes and text/plain mime-type

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'])) {
开发者_JS百科            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!


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.


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

sudo chmod -rf 777 dompdf
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜