问题描述
我正在尝试使用 fpdf 将文本包装在我的 pdf 的单元格上。 现在我按照 youtube 上的教程进行了多次故障排除,但我不确定为什么它占据了第二行。 参考链接:https://www.youtube.com/watch?v=utjJe90MeEw
代码如下:
$details="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s";
$result="It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.";
$interpretation="Contrary to popular belief,Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC,making it over 2000 years old.";
$remarks="Contrary to popular belief,making it over 2000 years old.";
$pdf->Ln(8);
$pdf->SetFont('Times','B',11);
$pdf->SetTextColor(39,39,39);
$pdf->Cell(185,10,'LABORATORY TEST RESULTS',1,'C');
$data=array(
array(
"Laboratory Test Performed:",$details
),array(
"Test Result:",$result
),array(
"Interpretation:",$interpretation
),array(
"Remarks:",$remarks
),);
//Laboratory Results
foreach($data as $item)
{
$cellWidth=125; //wrapped cell width
$cellHeight=6; //normal one-line cell height
//check whether the text is overflowing
if($pdf->GetStringWidth($item[1])<$cellWidth)
{
$line=1;
}
else
{
$textLength=strlen($item[1]); //total text length
$errMargin=10; //cell width error margin,just in case
$startChar=0; //character start position for each line
$maxChar=0; //maximum character in a line,to be incremented later
$textArray=array(); //to hold the strings for each line
$tmpString=""; // to hold the string
while($startChar<$textLength)
{
while($pdf->GetStringWidth($tmpString)<($cellWidth-$errMargin) &&
($startChar+$maxChar)<$textLength)
{
$maxChar++;
$tmpString=substr($item[1],$startChar,$maxChar);
}
$startChar=$startChar+$maxChar;
array_push($textArray,$tmpString);
$maxChar=0;
$tmpString='';
}
$line=count($textArray);
}
$pdf->SetFont('Times','',10);
$pdf->SetTextColor(52,52,53);
$pdf->SetDrawColor(131,131,133);
$pdf->Cell(65,($line*$cellHeight),$item[0],0);
$xPos=$pdf->GetX();
$yPos=$pdf->GetY();
$pdf->SetFont('Times',53);
$pdf->Multicell($cellWidth,$cellHeight,$item[1],1);
}
我不明白为什么会发生这种情况。第一行的第一个单元格试图占据第二行,第二行有这条线。有人能帮我解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)