我在CodeIgniter中使用mPDF.
这是我的lib(pdf.php)
class pdf {
function pdf()
{
$CI = & get_instance();
log_message('Debug', 'mPDF class is loaded.');
}
function load($param=NULL)
{
include_once APPPATH.'/third_party/mpdf/mpdf.php';
if ($params == NULL)
{
$param = '"en-GB-x","A4","","",10,10,10,10,6,3,"L"';
}
return new mPDF($param);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器
$filename = 'qwerty';
//...
// As PDF creation takes a bit of memory, we're saving the created file in /downloads/reports/
$pdfFilePath = FCPATH."reports\\" . $filename . ".pdf";
//$data['page_title'] = 'Hello world'; // pass data to the view
for($i=0;$i>=0;$i++)
{
if(file_exists($pdfFilePath) == TRUE)
{
$pdfFilePath = FCPATH."reports\\" . $filename . $i . ".pdf";
} else {
break 1;
}
}
ini_set('memory_limit','32M');
$html = $this->load->view('certificate/certificate', $isi,TRUE); // render the view into HTML
$this->load->library('pdf');
$pdf = $this->pdf->load($param);
\$pdf = $this->pdf->load();
$pdf->SetFooter($_SERVER['HTTP_HOST'].'|{PAGENO}|'.date(DATE_RFC822));
$pdf->WriteHTML($html);
$pdf->Output($pdfFilePath, 'F'); // save to file because we can
Run Code Online (Sandbox Code Playgroud)
即使使用那个config($param),结果仍然会给我一个肖像文件,因此,CSS内部非常混乱.
我该怎么办?
小智 12
我的名字是Rhonald Brito,这是我第一次来这里,我使用Codeigniter和MPDF大约1年,在这里我告诉你我的代码:
public function Make_PDF($view, $data, $file_name) {
$html = $this->load->view($view, $data, true);
$this->mpdf = new mPDF();
$this->stylesheet = file_get_contents('css/style.css');
$this->mpdf->AddPage('L', // L - landscape, P - portrait
'', '', '', '',
30, // margin_left
30, // margin right
30, // margin top
30, // margin bottom
18, // margin header
12); // margin footer
$this->mpdf->WriteHTML($html);
//$this->mpdf->Output($file_name, 'D'); // download force
$this->mpdf->Output($file_name, 'I'); // view in the explorer
// for more information rhonalejandro@gmail.com
}
Run Code Online (Sandbox Code Playgroud)