【发布时间】: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->render()来检查是否有错误。
标签: php mime-types kohana-3 dompdf filesize