Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the page in landscape mode in mpdf?

Tags:

php

mpdf

I am using mpdf library in PHP to create a pdf file from HTML. I need to set the page mode in landscape mode.

Here is the code I am using :

$mpdf=new mPDF('c'); 

$mpdf->WriteHTML($html);
$mpdf->Output();
exit;

However, this is setting the page mode in portrait mode. Any idea, how to set the landscape mode in mpdf ?

like image 653
Kiran Avatar asked Dec 30 '13 15:12

Kiran


People also ask

How do I set mPDF to landscape?

$mpdf=new mPDF('c', 'A4-L'); “-L” is used to force the Landscape page orientation of document.

How do I set margins in mPDF?

In standard usage, mPDF sets the following: margin-top = distance in mm from top of page to start of text (ignoring any headers) margin-header = distance in mm from top of page to start of header. margin-bottom = distance in mm from bottom of page to bottom of text (ignoring any footers)

What is mPDF format?

mPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence.

How do I add a page in mPDF?

If writing a DOUBLE-SIDED document, a conditional page-break ( $type = "E" or "O" ) will add a new page only if required to make the current page match the type (i.e. ODD or EVEN); a page-break with $type = "NEXT-ODD" or "NEXT-EVEN" will add one or two pages as required to make the current page match the type (i.e. ODD ...


2 Answers

You can do that by adding -L to your page format. So in our case you'd add another param to your constructor:

$mpdf = new mPDF('c', 'A4-L'); 

More about mPDF constructor params can be found here(deadlink).

like image 187
MaGnetas Avatar answered Sep 28 '22 03:09

MaGnetas


In mPDF version 7.0.0 or later the configuration need to be parsed as array[]:

$myMpdf = new Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4-L',
    'orientation' => 'L'
]

In older version before version 7.0.0. it need to be done like this:

myMpdf = new mPDF(
    '',    // mode - default ''
    'A4-L',    // format - A4, for example, default ''
    0,     // font size - default 0
    '',    // default font family
    15,    // margin_left
    15,    // margin right
    16,    // margin top
    16,    // margin bottom
    9,     // margin header
    9,     // margin footer
    'L'    // L - landscape, P - portrait
);
like image 24
lin Avatar answered Sep 28 '22 04:09

lin