#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Greater Crater of Sudbury
    Posts
    51
    Rep Power
    10

    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.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    1
    Rep 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...f-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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep 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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep 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-->

IMN logo majestic logo threadwatch logo seochat tools logo