首页 > 解决方案 > 如何将MPDF生成的第一页设置为横向

问题描述

假设您知道如何在 PHP 中使用 MPDF 库,这是我实例化该类对象的代码:

....
$marginFooter = 10;
$orientation = 'landscape';
$mpdf = new mPDF('en-x','A4','','',$marginLeft, $marginRight, $marginTop, $marginBottom, $marginHeader, $marginFooter, $orientation);
....

生成的 PDF 的第一页仍然是纵向的。即使在上述代码下方添加这一行也无济于事:

$mpdf->DefOrientation = 'landscape';

如果我将此标签添加为 PDF 的 HTML 正文中的第一个标签:

<body>
<pagebreak orientation="landscape"></pagebreak>
</body>

第一页为空白和纵向;第二个是风景。

如何使首页横向

标签: phpmpdf

解决方案


不确定您使用的是什么版本。但是对于版本:≥ 7.0 使用值 'P' 或 'L' 作为您的方向,如下所示:

    $marginFooter = 10;
    $orientation = 'L';
    $mpdf = new mPDF('en-x','A4','','',$marginLeft, $marginRight, $marginTop, $marginBottom, $marginHeader, $marginFooter, $orientation);

从文档:

方向

如果将格式定义为数组,则此属性指定新文档的默认页面方向。如果 format 是字符串值,则该值将被忽略。

默认值:'P'

值(不区分大小写)

“P”:肖像

“L”:风景

参考:

https://mpdf.github.io/reference/mpdf-functions/construct.html


推荐阅读