gpt4 book ai didi

MPdf - 全页尺寸图像,但仅适用于单页

转载 作者:行者123 更新时间:2023-12-02 08:18:24 30 4
gpt4 key购买 nike

我知道有类似的问题,但没有一个能解决我的问题。我想用 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
...

下面的代码以拉伸(stretch)图片的方式,我想实现:

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

...

关于MPdf - 全页尺寸图像,但仅适用于单页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39860714/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com