FPDF cell does not fill with color and gets a line break that I do not want

0

Good afternoon everyone!

I am a newbie with FPDF and I notice a lot, I have a problem with cell and it is not filling the cell as I want and also I get a line break strong> (in a multicell that goes just below) that I do not want, can you help me?

pdf->SetXY($pdf->GetX(),$pdf->GetY());          
$pdf->SetTextColor(0,0,0);  
$pdf->SetFillColor(111,222,255); 
$pdf->Cell(20, 0, 'Orden', 1, 1, 'L', True); 
$pdf->SetXY($pdf->GetX()+20,$pdf->GetY());      
$pdf->Cell(20,0,'2',1,1,'L',True);  
$pdf->SetXY($pdf->GetX()+40,$pdf->GetY()); 
$pdf->Cell(20,0,'Tono',0,1,'L',True);  
$pdf->SetXY($pdf->GetX()+60,$pdf->GetY()); 
$pdf->SetFillColor(0,0,255);
$pdf->Cell(22,0,'',0,1,'L',True);  
$pdf->SetXY($pdf->GetX()+82,$pdf->GetY()); 
$pdf->Cell(20,0,'Gama',0,1,'L',True);  
$pdf->SetXY($pdf->GetX()+102,$pdf->GetY()); 
$pdf->SetFillColor(0,0,255);
$pdf->Cell(20,0,'',0,1,'L',True);

$pdf->SetXY($pdf->GetX(),$pdf->GetY()+3);  
$pdf->SetFont('Arial','B',11); 
$pdf->SetWidths(array(124));
$pdf->RowOscuro(array(utf8_decode("DESCRIPCIÓN")));

RowOscuro function:

    function RowOscuro($data)
{
    $nb=0;
    for($i=0;$i<count($data);$i++)
        $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
    $h=8*$nb;
    $this->CheckPageBreak($h);
    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
        $x=$this->GetX();
        $y=$this->GetY();
        $this->Rect($x,$y,$w,$h);
        $this->SetFillColor(122,196,117); //relleno
        $this->SetDrawColor(255,255,255); //borde
        $this->SetTextColor(0,0,0); //letra
        $this->MultiCell($w,8,$data[$i],1,$a,'true');
        $this->SetXY($x+$w,$y);
    }
    $this->Ln($h);
}

The idea is that 6 cells would come out, from left to right they would be:

| Order | 2 | Tone | cell without text filled with blue | Range | cell without text filled with blue |

    
asked by wiki 01.03.2018 в 18:31
source

2 answers

1

The problem is because you are passing the parameters wrong to the Cell method; These are:

  

Cell (float w [ float h [ string txt [ mixed border [ int ln [ string align [ boolean fill [ mixed link]]]]]]))

Where:

  

w : Cell width. If 0, these extend to the right margin of the page.
h : Height of the cells.
txt : String to print .% ln : Indicates where the current position should go before invoking. The possible values are: 0 (on the right), 1 (at the beginning of the next line) or 2 below.
border Indicates whether the edges should be drawn around the block the cell. The value can be a number: 0 (no edge), 1 (frame)
  or a string containing some or all of the following characters (in any order): L (left), T (top) R (right) or B (bottom).   Default value: 0.
align : Sets the text alignment. The possible values are:    L (alignment to the left), C (centered), R (alignment to the right) or J (justification). Default value J .
fill : Indicates whether the bottom of the cell should be drawn ( true ) or transparent ( false ). Default value: false .
link : URL or identifier returned by AddLink ().

Solution:

  • You must indicate the height of the cell ( h ), otherwise only a finite line will be seen.
  • If you indicate the position where you should go ( ln ) equal to zero ( 0 ), you can save yourself having to manipulate the xy .

Code:

$pdf->SetXY($pdf->GetX(),$pdf->GetY()); 
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFillColor(111, 222, 255);
$pdf->Cell(20, 10, 'Orden', 1, 0, 'L', true);
$pdf->Cell(20, 10, '2', 1, 0, 'L', true);
$pdf->Cell(20, 10, 'Tono', 1, 0, 'L', true);
$pdf->SetFillColor(0, 0, 255);
$pdf->Cell(22, 10, '', 1, 0, 'L', true);
$pdf->Cell(20, 10, 'Gama', 1, 0, 'L', true);
$pdf->SetFillColor(0, 0, 255);
$pdf->Cell(20, 10, '', 1, 0, 'L', true);
$pdf->Ln(3);

$pdf->SetFont('Arial','B',11); 
$pdf->SetWidths(array(124));
$pdf->RowOscuro(array(utf8_decode("DESCRIPCIÓN")));
    
answered by 01.03.2018 / 19:24
source
0

I have solved it like this:

pdf->SetXY($pdf->GetX(),$pdf->GetY());          
$pdf->SetTextColor(0,0,0);  
$pdf->SetFillColor(111,222,255); 
$pdf->Cell(20, 8, 'Orden', 1, 1, 'L', 'true'); // Si en el segundo parámetro pones 0 te coge el alto de la fila como 0, leugo en vez de True, he puesto 'true'
...

$pdf->SetXY($pdf->GetX(),$pdf->GetY());  // El GetY()+3 metía el salto de línea
$pdf->SetFont('Arial','B',11); 

$pdf->SetWidths(array(124));
$pdf->RowOscuro(array(utf8_decode("DESCRIPCIÓN")));
    
answered by 01.03.2018 в 19:14