当按下回车键时,在单元格中添加一行

时间:2019-05-13 16:20:24

标签: php fpdf

所以我刚在fpdf上检测到一个问题,当我将说明写到多单元格时,按Enter键以换行并发生这种情况

Image with problem

但是我的多单元格代码被编程为计算字符串大小,并且当大小大于单元格的宽度时,它会广告一条折线并且高度大小会变大,但是当我按Enter时,只需添加相同的高度 例子

“我叫João”->身高= 6.5

“我叫João,(换行符),我正在使用fpdf”-> height = 6.5 + 6.5而不是height = 6.5 + 1

这是我的pdf文件,无需按Enter

Image

这是我的pdf文件,具有多单元格功能

Image

我将保留计算所有多单元电池内容的代码。


$size = $pdf-> h;  // page size

$cellWidth=120;   // width da cell
$cellHeight=6.5;  // height da cell

// verificar se o texto passa a cell

if($pdf->GetStringWidth(iconv('UTF-8', 'windows-1252',$r['description'])) < $cellWidth){
       //doesn't do anything because when line is multiplied it receives the same value ( 6.5 * 1 = 6.5 )
      $line = 1;
}else{
       $line = ceil($pdf->GetStringWidth(iconv('UTF-8', 'windows-1252',$r['description'])));
       $line = round($line / $cellWidth,0) + 1;
}

// use multicell instead of cell
// as a MultiCell is always treated as end of line, 
// manually set the xy position to the next cell being next.
// save a position x before writing a multicell

$xPos=$pdf->GetX();
$yPos=$pdf->GetY();
$total = $yPos + ($line * $cellHeight);

if ($total > $size - 30) { // $size = $totalheight // change page
       $pdf->AddPage();      // add page
       $xPos=$pdf->GetX();
       $yPos=$pdf->GetY();
}
$sizecell = $pdf->GetMultiCellHeight($cellWidth, $cellHeight,iconv('UTF-8', 'windows-1252',$r['description']));
$pdf->MultiCell($cellWidth,$cellHeight,iconv('UTF-8', 'windows-1252',$r['description']),'LBR','L');



// receive the position of the cell after multicell
// equals the x with the height of the multicell
$pdf->SetXY($xPos + $cellWidth , $yPos);
// write cells


// as the variable $cellHeight is multiplied by the value of the line is going to be greater than $cellHeight
// of the multicell so we need to make a loop and subtract 0.01 until the value is the same as the multicell

$cell = $line * $cellHeight;


if ($cell > $sizecell){
   while($cell > $sizecell){
        $cell = $cell - 0.01;
   }
} else {
   $cell = $cell;
}

$pdf->Cell(15,($cell),$r['quantity'],'LBR',0);          
$pdf->Cell(10,($cell),'UNI','LBR',0);
$pdf->Cell(25,($cell),$r['priceuni'].chr(128),'LBR',0);
$pdf->Cell(25,($cell),$r['sum'].chr(128),'LBR',1); 


我接受任何建议,我不知道该怎么做

0 个答案:

没有答案