【问题标题】:MPDF how to use alpha transparent?MPDF如何使用alpha透明?
【发布时间】:2021-03-07 16:02:04
【问题描述】:

我使用 MPDF 创建具有整页背景的 pdf 文件。我想像这张图片一样在上面做一个布局。

我认为需要使用 alpha 透明,但我不知道如何

这是我的代码

<?php
$pdfOptions = array(
    'mode'              => 'utf-8',
    'format'                => 'A4-L',
    'img_dpi'               => 300,
    'dpi'                   => 300,
);
require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf($pdfOptions);

//==============================================================

$html='
<style>
#cover {
  background-color: #dddddd;

}
</style>

<div id="cover" style="position: absolute; left:0; right: 0; top: 0; bottom: 0; width: 297mm; height: 50mm;">
</div>
';

$mpdf->WriteHTML("<html><body style='background-image:url(\"images/1.jpg\"); background-image-resize: 5; background-position: top center;'></body></html>");

$mpdf->WriteHTML($html);
$mpdf->WriteHTML('<p>Text for item 1</p>');

$mpdf->Output(); 
exit;

?>

我正在尝试使用不透明度

#cover {
width: 297mm;
 height: 50mm;
  background-image: url("images/b.png");
  background-image-resize: 5;
  background-position: center center;
  background-image-opacity: 0.5;

}

但是结果是这样的

【问题讨论】:

  • opacity 样式属性怎么样,或者为background-color 使用#DDDDDD20 - 其中20 是不透明度(32/255 = 12.5%)
  • #DDDDDD20 不起作用,仅背景图像支持不透明度。我更新了关于不透明度的帖子

标签: php html css mpdf


【解决方案1】:

rgba 是supported by mPDF,所以样式应该是这样的,其中last是alpha值:

<style>
#cover {
  background-color: rgba(221, 221, 221, 0.5);
}
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多