php - 如何将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>
第一页为空白和纵向;第二个是风景。
如何使首页横向?
解决方案
不确定您使用的是什么版本。但是对于版本:≥ 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
推荐阅读
- java - 出现错误:(20, 44) java: constructor XXX cannot be applied to given types;
- java - 无法取消 WorkerThread 。什么时候做取消功能,还是执行
- c# - 在接口(EntityFramework)编辑连接字符串
- firebase - 反应原生 Firebase signOut()
- c - 在 PC 上安装 gcc 并出现几个错误
- sql - SQL - 查询优化
- github - How can I create relative links from my MarkDown to GitHub raw files?
- python - 如何在 html 烧瓶视图中将字符串转换为整数
- jquery - Making div element dynamic with another function
- python - pandas DataFrame:用对应列的中位数替换nan值