How to set the page in landscape mode in mpdf?

Viewed 63838

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 ?

8 Answers

The best way to change the orientation is to pass an array with arguments.

This variable gets passed to the constructor and is called $config

public function __construct(array $config = []){ }

Down below are the default configurations of the Mpdf

$default_config= [
                'mode' => '',
                'format' => 'A4',
                'default_font_size' => 0,
                'default_font' => '',
                'margin_left' => 15,
                'margin_right' => 15,
                'margin_top' => 16,
                'margin_bottom' => 16,
                'margin_header' => 9,
                'margin_footer' => 9,
                'orientation' => 'P',
            ];

To change the orientation from Portrait to Landscape just change the "orientation" parameter as it is written below.

$mpdf = new Mpdf(['orientation' => 'L']);

In mPDF version 7.2.1 works form me :

$mpdf = new \Mpdf\Mpdf(array('', '', 0, '', 15, 15, 16, 16, 9, 9, 'L'));

$mpdf->WriteHTML('<p>This is just a <strong>test</strong>, This is just a <strong>test</strong></p>');
$mpdf->Output();
Related