Overlap in the fpdf output in php

99封情书 提交于 2019-12-25 07:06:07

问题


Iam a beginner in using fdpf in php . I have searched a lot but couldn't find the solution

I need to get output like this

but the output of my code is

the code:

$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);

where $row1a,$row1b,$row1c are the variables used to fetch the question and marks from database. Since the question can be of variable length fetched from database , it overlaps with the next question.

Thanks in advance.


回答1:


try this on the overlapping row:

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

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



回答2:


Perform a GetY() update after every MultiCell() call (this pushes the current Y value every time downwards) and recalculate it properly for every further MultiCell().



来源:https://stackoverflow.com/questions/36193626/overlap-in-the-fpdf-output-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!