April 13th, 2005, 09:02 AM
FPDF function MultiCell( ) linewrap problems
good after ladies and gentlemen, most likely gentlemen. that just seems to be the way nowadays.
I'm trying to generate some reports using the FPDF class, and drawing out tables is proving to be difficult.
I have 6 columns, with the second column being the widest. This column also contains text that will most often wrap to the next line. I'm trying to use the MultiCell( ) function to achieve this.
The main problem that I'm having is that MultiCell()'s stack on top of each other. I can't get one MultiCell() to sit beside another MultiCell(). Is there any way to prevent a new line from being inserted after every MultiCell() is drawn?
If not, is there any way I can get text to wrap around inside a normal Cell() ?
Here is my code thusfar:
$header = array('title' => 'Account', 'width' => 40);
$header = array('title' => 'Description', 'width' => 70);
$header = array('title' => 'Type', 'width' => 20);
$header = array('title' => 'Tax', 'width' => 20);
$header = array('title' => 'Rebate', 'width' => 20);
$header = array('title' => 'Ret.', 'width' => 10);
$query = "select * from v_chartlistqy";
$result = mysql_query($query);
$rowHeight = 14;
while ($row = mysql_fetch_array($result))
$pdf->MultiCell($header['width'], $rowHeight, $row['account'], 1);
$pdf->MultiCell($header['width'], $rowHeight, $row['descr'], 1);
$pdf->MultiCell($header['width'], $rowHeight, $row['td'], 1);
$pdf->MultiCell($header['width'], $rowHeight, $row['tc'], 1);
$pdf->MultiCell($header['width'], $rowHeight, $row['rc'], 1);
January 21st, 2008, 01:58 PM
Use SetX() and SetY()
This post is old, but I came across it while encountering the same issue with wanting my line wraps to behave as cells. The solution I found was on this blog:
Basically you find the coordinates before you use the Multicell using GetX and GetY, and then do a little math afterwards and use SetX, and SetY.
Hope this helps anybody else with similar problems
$pdf->SetY($y); //set pointer back to previous values
March 15th, 2012, 10:13 PM
If somebody is trying to use it:
The SetY() must set before the SetX() because the SetY() is setting X-Coordinate back to default.
October 30th, 2012, 04:57 AM
Php Multicell alignment
<---For Word Wrap-->
$project =$row["project_title"]; <--replace project_title with url mysql parameter-->
$project_title = wordwrap($project, 20, "\n");
<--For each Multicells-->
$current_y = $this->GetY();
$current_x = $this->GetX();
$cell_width = 40;
$this->MultiCell($cell_width, 3, $project_title,0,'T', false,'T');
$this->SetXY($current_x + $cell_width, $current_y);
Use these functions for each and every multicells it will but without border lines-->