如何在mpdf中以横向模式设置页面?

Kir*_*ran 10 php mpdf

mpdf在PHP中使用库来从HTML创建pdf文件.我需要在landscape模式下设置页面模式.

这是我正在使用的代码:

$mpdf=new mPDF('c'); 

$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
Run Code Online (Sandbox Code Playgroud)

但是,这是在portrait模式下设置页面模式.任何想法,如何在mpdf中设置横向模式?

MaG*_*tas 31

您可以通过在页面格式中添加-L来实现.所以在我们的例子中你要为你的构造函数添加另一个参数:

$mpdf = new mPDF('c', 'A4-L'); 
Run Code Online (Sandbox Code Playgroud)

有关mPDF构造函数参数的更多信息,请参见此处


Rav*_*kam 9

这可能对您有用.

最后一个参数是方向.

class mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
Run Code Online (Sandbox Code Playgroud)

P:DEFAULT肖像

L:风景

"-L"强制执行Landscape页面方向

// Define a Landscape page size/format by name
$mpdf=new mPDF('utf-8', 'A4-L');

// Define a page using all default values except "L" for Landscape orientation
$mpdf=new mPDF('','', 0, '', 15, 15, 16, 16, 9, 9, 'L');
Run Code Online (Sandbox Code Playgroud)

你可以在这里挖掘更多


aeb*_*old 8

检查mPDF构造函数的文档.

$mpdf=new mPDF('c', 'A4-L'); 
Run Code Online (Sandbox Code Playgroud)


lin*_*lin 7

在 mPDF 7.0.0或更高版本中,配置需要解析为array[]

$myMpdf = new Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4-L',
    'orientation' => 'L'
]
Run Code Online (Sandbox Code Playgroud)

在7.0.0版之前的旧版本中。它需要这样做:

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
);
Run Code Online (Sandbox Code Playgroud)


Maz*_*tov 6

添加这样的选项:

 $mpdf = new mPDF('',    // mode - default ''
 '',    // 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
Run Code Online (Sandbox Code Playgroud)


Sib*_* PR 0

你好,去这里找到那个。AddPage() 有参数来设置......

$mpdf->AddPage('L',.....);
Run Code Online (Sandbox Code Playgroud)