我知道有类似的问题,但没有一个能解决我的问题。我想对 mPDF 执行以下操作:
Page 1: Text for item 1
Page 2: Full width and height image to cover the page with an image of item 1
Page 3: Text for item 2
Page 4: Full width and height image to cover the page with an image of item 2
...
下面的代码以我想要实现的方式拉伸图像:
body {
background-image:url("image1.jpg");
background-image-resize: 5;
background-position: top center;
}
但这会导致在每个页面上设置图像(我知道,它是 body 元素)。所以我尝试了以下方法:
<div style='
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:url("image1.jpg");
background-image-resize: 5;
background-position: top center;
'></div>
但这是行不通的。所以我尝试了相同的代码,只是使用颜色,而不是图像:
<div style='
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #F00;
'>
</div>
<div style="page-break-before: always;"></div>
这正在发挥作用。整个页面都是红色的。那么如何用图像实现同样的效果呢?
有任何想法吗?
经过多次尝试后,我发现最简单的方法就是将 HTML 代码分割成单独的部分,并通过单独的 WriteHtml 调用插入它们。例如:
// Create object
$mpdf = new \mPDF('utf-8');
// Create first text page
$mpdf->WriteHTML('<p>Text for item 1</p>');
// Add a new page with the image
$mpdf->AddPage();
$mpdf->WriteHTML("<html><body style='background-image:url(\"image1.jpg\"); background-image-resize: 5; background-position: top center;'></body></html>");
// Create second page
$mpdf->AddPage();
$mpdf->WriteHTML('<p>Text for item 1</p>');
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)