CodeIgniter页面方向的mPDF不会横向显示

问题描述 投票:4回答:5

我正在CodeIgniter中使用mPDF。

这是我的库(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);
    }
}

这是我的控制器

$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

即使使用该配置($param),结果仍然会生成我的肖像文件,因此,内部的CSS相当混乱。

我该怎么办?

codeigniter mpdf
5个回答
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
}

4
投票

创建新PDF时,请使用以下内容将其设置为横向

$mpdf = new mPDF('utf-8', 'L');

希望这会有所帮助

更多信息here


4
投票

在构造函数中将格式设置为'A4-L'。


1
投票

我使用与您相同的代码,并在我的代码中添加Rhonald Brito的代码。效果很好

 $pdf->AddPage('L', // L - landscape, P - portrait
        '', '', '', '',
        30, // margin_left
        30, // margin right
        30, // margin top
        30, // margin bottom
        18, // margin header
        12); // margin footer

0
投票

[阅读Using mPDF with CodeIgniter以查看将参数传递到何处并应用Pooshonk的建议参数后,在Codeigniter项目的助手中,使用适合mPDF的语法将所有页面设置为“横向”模式,达到了预期的效果。

$CI = get_instance();
$CI->load->library('pdf');
$html = $CI->load->view($templatePath, $dataArray, true);
$pdf = $CI->pdf->load('utf-8', 'L');

ps.s。经过更多的实验后,我发现传递true具有相同的效果。我认为它允许mPDF自动确定所提供数据的更合适的方向。如果是这样,它会更灵活,但可能还需要更多处理(当我知道]我总是想要此特定模板的横向时)。

$pdf = $CI->pdf->load(true);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.