重叠在PHP的FPDF输出(Overlap in the fpdf output in php)

2019-11-04 04:37发布

荫在PHP中使用fdpf一个初学者。 我已经搜索了很多,但找不到解决方案

我需要输出这样

但我的代码的输出

编码:

$row1a=mysql_fetch_array($sql_1a);
$row1b=mysql_fetch_array($sql_1b);
$row1c=mysql_fetch_array($sql_1c);

$pdf->Cell(6,6," 1 a) ",0,0);
$x = $pdf->GetX();
$y = $pdf->GetY();  
$pdf->MultiCell(150,6,"{$row1a['Question']}",0,1);
$pdf->SetXY($x + 160, $y);
$pdf->Cell(6,6,"{$row1a['Mark']}",0,1);

$pdf->Cell(6,6," b) ",0,0);
$x = $pdf->GetX();
$y = $pdf->GetY();          
$pdf->MultiCell(150,6,"{$row1b['Question']}",0,1);
$pdf->SetXY($x + 160, $y);
$pdf->Cell(6,6,"{$row1b['Mark']}",0,1);

$pdf->Cell(6,6," c) ",0,0);
$x = $pdf->GetX();
$y = $pdf->GetY();  
$pdf->MultiCell(150,6,"{$row1c['Question']}",0,1);
$pdf->SetXY($x + 160, $y);
$pdf->Cell(6,6,"{$row1c['Mark']}",0,1);

其中$ row1a,$ row1b,$ row1c是用来获取数据库的问题和标记的变量。 因为这个问题可以从数据库中读取的可变长度,它与下一个问题重叠。

提前致谢。

Answer 1:

试试这个在重叠行:

$height =  round(strlen($row1b['Question']) / 35);
$height = ($height < 1 ? 1 : $height);
$height = $height * 6;

$pdf->MultiCell(150,$height,"{$row1b['Question']}",0,1);


Answer 2:

执行GetY()每次更新后MultiCell()调用(每次都向下推动当前Y值),并适当重新计算每一个进一步MultiCell()



文章来源: Overlap in the fpdf output in php
标签: php fpdf