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 ?
$mpdf=new mPDF('c', 'A4-L'); “-L” is used to force the Landscape page orientation of document.
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)
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.
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 ...
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).
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
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With