RIRedinPA Posted October 9, 2009 Share Posted October 9, 2009 Hi. I'm trying to take some tabular data from a website and allow the user to print out a PDF copy of it. I've been able to flow the data from a MySQL db into a PDF using FPDF but I've run into an issue when a cell would contain a large amount of text. What I've set up (based on the FPDF tutorials) is a function which accepts two arrays, one for headers, the other for the tabular data. Run first loop to output the headers. Run a second to get the data, within that loop I run a stand alone loop to get all the text of each cell of row x. I get the length of that text and if it is > 20 characters do a little map to figure out what the max height of each cell will be in that row and then apply it to all cells of that row. That all works dandy except after the first MultiCell the following cells are pushed to the next line. For example, if cell 2 of row 2 meets the greater than 20 character check the table for the PDF is created as such R1C1 | R1C2 | R1C3 | R1C4 | R1C5 R2C1 | R2C2 | <Page Break - which is fine, it's the height of the cell causing this> R2C3 | R2C4 | R2C5 R3C1 | R3C2 | R3C3 | R3C4 | R3C5 R2C3 + all have the correct height but they are not in the correct location. I've tried (based on Google searches) to adjust the XY location by using SetXY() but regardless of what coordinates I put in the layout of the page doesn't change. My suspicion is because the next line in on the next page. Code follows, any help would be appreciated: include ("lib/config.php"); class PDF extends FPDF { function BasicTable($headerarray,$textarray) { //Header $this->SetTextColor(33,33,33); $this->SetDrawColor(0,0,0); $this->SetLineWidth(.3); $this->SetFont('Arial', 'b', '7'); foreach($headerarray as $col) { $this->Cell(21,7,$col,1, '', 'C'); }//end loop through headerarray $this->Ln(); //text formats $this->SetTextColor(0,0,0); $this->SetFillColor(200,200,200); $this->SetFont('Arial', 'i', '6'); //Data $fill = true; foreach($textarray as $row) { //determine the max height of the cells $maxH = 0; foreach($row as $text) { $linecount = ceil(strlen($text)/20); if (($linecount * 7.85) > $maxH) { $maxH = ($linecount * 7.85); } } //display data $cellnum = 0; foreach($row as $text) { if ($cellnum == 0) { //get text length if (strlen($text) > 20) { $this->MultiCell(21,6,$text,1, 0, 'L', $fill); } else { $this->Cell(21,$maxH,$text,1, 0, 'L', $fill); } } else { //get current x coordinate $x = $this->GetX(); $y = $this->GetY(); $this->SetXY(100,200); //get text length if (strlen($text) > 20) { $this->MultiCell(21,$maxH,$text,1, 0, 'L', $fill); } else { $this->Cell(21,$maxH,$text,1, 0, 'L', $fill); } } } $fill=!$fill; $this->Ln(); //increase cellnum $cellnum++; }//end loop through $row } //end loop through textarray }//end function //}//end class Link to comment https://forums.phpfreaks.com/topic/177114-fpdf-help-setxy/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.