MPDF page orientation CodeIgniter will not do landscape

I am using mPDF in CodeIgniter.

here is my 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); } } 

this is my controller

 $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 

even with this configuration ( $param ), the result still gives me a portrait file, so the CSS inside is pretty confusing.

What should I do?

+4
source share
5 answers

My name is Ronald Brito, this is my first time here, I have about 1 year using Codeigniter and MPDF, here I found out my code:

 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 } 
+12
source

When creating a new PDF, use the following to set it to landscape

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

Hope this helps

More info here

+4
source

Set the format to ā€œA4-Lā€ in the constructor.

+4
source

I use the same code as yours and add the Rhinod Brito code on mine. it works well

  $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 
+1
source

Having read Using mPDF with CodeIgniter to see where to pass my parameters, and applying the parameters suggested by Pooshonk, I got the desired effect by setting all the pages in Landscape mode with the syntax suitable for mPDF, in my Codeigniter project assistant ..

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

postscript Having experimented a bit with mPDF6.0 in my CI project, I found that passing true has the same effect. I assume this allows mPDF to automatically determine a more appropriate orientation for the data provided. If true, it is more flexible, but probably also requires a bit more processing (when I know that I always want landscape orientation for this particular template).

 $pdf = $CI->pdf->load(true); 
0
source

All Articles