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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20842347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:36:32  来源:igfitidea点击:

How to set the page in landscape mode in mpdf?

phpmpdf

提问by Kiran

I am using mpdflibrary in PHP to create a pdf file from HTML. I need to set the page mode in landscapemode.

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

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 portraitmode. Any idea, how to set the landscape mode in mpdf ?

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

回答by MaGnetas

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

您可以通过在页面格式中添加 -L 来实现。因此,在我们的示例中,您需要向构造函数添加另一个参数:

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

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

可以在此处找到有关 mPDF 构造函数参数的更多信息(死链接)。

回答by RaviRokkam

This may be useful for you.

这可能对您有用。

The last Parameter is orientation.

最后一个参数是方向。

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 ]]]]]])

P: DEFAULT Portrait

P:默认人像

L: Landscape

L:风景

"-L" to force a Landscape page orientation

“-L”强制横向页面方向

// 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');

You can dig more into it here

你可以在这里深入了解

回答by aebersold

Check the docs for the mPDF constructor.

检查mPDF 构造函数的文档。

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

回答by Mazeltov

add options like this:

添加如下选项:

 $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

回答by lin

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

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

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


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

在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
);

回答by Neo Morina

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

这个变量被传递给构造函数并被调用 $config

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

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

Down below are the default configurations of the Mpdf

下面是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']);

回答by user8376095

In mPDF version 7.2.1 works form me :

在 mPDF 7.2.1 版中,我的作品:

$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();

回答by Sibiraj PR

Hi go for here to find that. AddPage() have the parameter to set that....

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

$mpdf->AddPage('L',.....);