首页 > 解决方案 > 超过渐变时,Tcpdf multiCell 边框丢失

问题描述

如何在渐变上使用带有边框的 MultiCell?

在此处输入图像描述

请注意,如果您使用单元格,则会显示边框。

// set colors for gradients (r,g,b) or (grey 0-255)
$red = array(255, 0, 0);
$blue = array(0, 0, 200);
$yellow = array(255, 255, 0);
$green = array(0, 255, 0);
$white = array(255);
$black = array(0);

// set the coordinates x1,y1,x2,y2 of the gradient (see linear_gradient_coords.jpg)
$coords = array(0, 0, 1, 0);

// paint a linear gradient
$pdf->LinearGradient(20, 45, 80, 80, $red, $blue, $coords);

// write label
$pdf->MultiCell(100, 100, 'LinearGradient()', 1);

标签: phptcpdf

解决方案


根据 Nicola 本身(https://sourceforge.net/p/tcpdf/bugs/236/)“这是通缉行为”。

$pdf->setPageMark()在渐变和多单元格之间添加。

// paint a linear gradient
$pdf->LinearGradient(20, 45, 80, 80, $red, $blue, $coords);

$pdf->setPageMark();

// write label
$pdf->MultiCell(100, 100, 'LinearGradient()', 1);

此外,通过setPageMarkdocblock:

在当前页面流上设置开始写入标记,用于放置边框和填充。边框和填充总是在内容之后创建并插入到此方法标记的位置。此函数必须在为背景图像调用 Image() 函数后调用。背景图像必须始终在调用 Multicell() 或 WriteHTMLCell() 或 WriteHTML() 函数之前插入。


推荐阅读