我在下面的codeigniter代码我正在处理pdf文件当我执行它时hello world只显示但不是表格请帮助我解决问题。我已将控制器放在下面。我从这个网站下载{{3 }}
控制器:
<?php
class Tutorial extends controller
{
function Tutorial()
{
parent::Controller();
$this->load->helper('url');
}
function index()
{
$this->hello_world();
}
function hello_world()
{
$this->load->library('cezpdf');
$this->cezpdf->ezText('Hello World', 12, array('justification' => 'center'));
$this->cezpdf->ezSetDy(-10);
$content = 'The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.';
$this->cezpdf->ezText($content, 10);
$this->cezpdf->ezStream();
}
function tables()
{
$this->load->library('cezpdf');
$db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
$db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
$db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');
$col_names = array(
'name' => 'Name',
'phone' => 'Phone Number',
'email' => 'E-mail Address'
);
$this->cezpdf->ezTable($table_data, $col_names, 'Contact List', array('width'=>550));
$this->cezpdf->ezStream();
}
function headers()
{
$this->load->library('cezpdf');
$this->load->helper('pdf');
prep_pdf(); // creates the footer for the document we are creating.
$db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
$db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
$db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');
$col_names = array(
'name' => 'Name',
'phone' => 'Phone Number',
'email' => 'E-mail Address'
);
$this->cezpdf->ezTable($db_data, $col_names, 'Contact List', array('width'=>550));
$this->cezpdf->ezStream();
}
}
?>
答案 0 :(得分:0)
尝试mPdf。将css样式的html直接转换为pdf。在CI上,您可以将参数化视图加载到mPdf并生成文档。如果你没有开始工作项目,你就可以做到。
答案 1 :(得分:-1)
您可以使用mPDF在Codeigniter中生成PDF。
您可以创建一个控制器类,然后在其中创建函数。然后做一些下面的代码 -
public function mypdf() {
$this->load->library('pdf');
$pdf = $this->pdf->load();
$html=$this->load->view('welcome_message',null,true);
$pdf->WriteHTML($html);
// write the HTML into the PDF
$output = 'itemreport' . date('Y_m_d_H_i_s') . '_.pdf';
$pdf->Output("$output", 'I');
}
有关详细信息,您可以将mPDF用于codeigniter。教程here。
OR
您可以尝试将DOMPDF用于codeigniter。教程here。