The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
FPDF function MultiCell( ) linewrap problems
Discuss FPDF function MultiCell( ) linewrap problems in the PHP Development forum on Dev Shed. FPDF function MultiCell( ) linewrap problems PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 13th, 2005, 09:02 AM
|
|
Contributing User
|
|
Join Date: Nov 2004
Location: Greater Crater of Sudbury
Posts: 51
Time spent in forums: 19 h 38 m 34 sec
Reputation Power: 9
|
|
|
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:
Code:
$header= array();
$header[0] = array('title' => 'Account', 'width' => 40);
$header[1] = array('title' => 'Description', 'width' => 70);
$header[2] = array('title' => 'Type', 'width' => 20);
$header[3] = array('title' => 'Tax', 'width' => 20);
$header[4] = array('title' => 'Rebate', 'width' => 20);
$header[5] = array('title' => 'Ret.', 'width' => 10);
require("../functions/db.inc");
db_connect("gl");
$query = "select * from v_chartlistqy";
$result = mysql_query($query);
$rowHeight = 14;
while ($row = mysql_fetch_array($result))
{
$pdf->MultiCell($header[0]['width'], $rowHeight, $row['account'], 1);
$pdf->MultiCell($header[1]['width'], $rowHeight, $row['descr'], 1);
$pdf->MultiCell($header[2]['width'], $rowHeight, $row['td'], 1);
$pdf->MultiCell($header[3]['width'], $rowHeight, $row['tc'], 1);
$pdf->MultiCell($header[4]['width'], $rowHeight, $row['rc'], 1);
$pdf->Ln();
}
$pdf->output();
Thanks.
|

January 21st, 2008, 01:58 PM
|
|
Registered User
|
|
Join Date: Jan 2008
Posts: 1
Time spent in forums: 9 m 49 sec
Reputation Power: 0
|
|
|
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:
http://www.roxxor.co.uk/blog/2007/10/05/wrapping-text-in-fpdf-table-cells/
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.
Example:
Code:
$x=16;
$y=26;
$width=100;
$height=35;
$leftmargin=16;
for ($r=0;$r<10;$r++){
for ($c=0;$c<6;$c++){
$pdf->SetY($y); //set pointer back to previous values
$pdf->SetX($x);
$x=$pdf->GetX()+$width;
$y=$pdf->GetY();
$pdf->MultiCell($width,$height,$r."-".$c." ".$x.",".$y,1,'L');
}
$y+=$height;
$x=$leftmargin;
$pdf->SetY($y);
}
Hope this helps anybody else with similar problems
|

March 15th, 2012, 10:13 PM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 1
Time spent in forums: 13 m 17 sec
Reputation Power: 0
|
|
|
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
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 9 m 54 sec
Reputation Power: 0
|
|
|
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);
<--end-->
Use these functions for each and every multicells it will but without border lines-->
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|