Kohana 3 と pdfview/DOMPDF を使用して pdf ファイルを生成していますが、それらは 0 バイトと text/plain 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));
}
}
今、それは働いています。ありがとう!