How can I adjust the cells of this FPDF document?

2

Greetings, I am trying to adjust this FPDF document (the header of each column) but I can not find it, I do not find where I have to adjust so that they appear next to each other after the 4th one throws it down.

<?php
require('fpdf.php');
$con=mysqli_connect('localhost','root','12345678');
mysqli_select_db($con,'pacientes');


class PDF extends FPDF {
	function Header(){
		$this->SetFont('Arial','B',15);
		
		//dummy cell to put logo
		//$this->Cell(12,0,'',0,0);
		//is equivalent to:
		$this->Cell(12);
		
		//put logo
		$this->Image('logo-small.png',10,10,10);
		
		$this->Cell(100,10,'Lista de pacientes',0,1);
		
		//dummy cell to give line spacing
		//$this->Cell(0,5,'',0,1);
		//is equivalent to:
		$this->Ln(5);
		$this->SetFont('Arial','B',11);
		
		$this->SetFillColor(180,180,255);
		$this->SetDrawColor(180,180,255);
		$this->Cell(40,5,'Nombre ',1,0,'',true);
		$this->Cell(25,5,'Apellido',1,0,'',true);
		$this->Cell(20,5,'Edad',1,0,'',true);
		$this->Cell(30,5,'Sexo',1,1,'',true);
		$this->Cell(30,5,'Sexo',1,1,'',true);
		$this->Cell(30,5,'Sexo',1,1,'',true);
		$this->Cell(30,5,'Sexo',1,1,'',true);

		
	}
	function Footer(){
		//add table's bottom line
		$this->Cell(190,0,'','T',1,'',true);
		
		//Go to 1.5 cm from bottom
		$this->SetY(-15);
				
		$this->SetFont('Arial','',8);
		
		//width = 0 means the cell is extended up to the right margin
		$this->Cell(0,10,'Page '.$this->PageNo()." / {pages}",0,0,'C');
	}
}


//A4 width : 219mm
//default margin : 10mm each side
//writable horizontal : 219-(10*2)=189mm

$pdf = new PDF('L','mm',array(600,300)); //use new class

//define new alias for total page numbers
$pdf->AliasNbPages('{pages}');

$pdf->SetAutoPageBreak(true,15);
$pdf->AddPage();

$pdf->SetFont('Arial','',9);
$pdf->SetDrawColor(180,180,255);

$query=mysqli_query($con,"select * from datosbasicos");
while($data=mysqli_fetch_array($query)){
	$pdf->Cell(40,5,$data['NOM_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['APE_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['EDAD_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['SEX_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['TEL_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['CEL_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['HIS_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['DIR_PAC'],'LR',0);
	$pdf->Cell(25,5,$data['DIR_PAC'],'LR',0);
	
	if($pdf->GetStringWidth($data['email']) > 65){
		$pdf->SetFont('Arial','',7);
		$pdf->Cell(65,5,$data['email'],'LR',0);
		$pdf->SetFont('Arial','',9);
	}else{
		$pdf->Cell(65,5,$data['email'],'LR',0);
	}
	$pdf->Cell(60,5,$data['address'],'LR',1);
}














$pdf->Output();
?>
    
asked by Pablo Pernia 22.08.2017 в 07:44
source

1 answer

5

After the fourth they appear below because that is what the code specifies.

If you notice, in the first three flames to the function Cell as follows:

$this->Cell(40,5,'Nombre ',1,0,'',true);
$this->Cell(25,5,'Apellido',1,0,'',true);
$this->Cell(20,5,'Edad',1,0,'',true);

The fifth parameter indicates where the cursor should move after drawing the cell. 0 indicates that you should move to the right.

In contrast, in the others you have a 1 :

$this->Cell(30,5,'Sexo',1,1,'',true);
$this->Cell(30,5,'Sexo',1,1,'',true);
$this->Cell(30,5,'Sexo',1,1,'',true);
$this->Cell(30,5,'Sexo',1,1,'',true);

The 1 indicates that the cursor passes to the beginning of the next line after drawing the cell.

If you want them to appear one after the other you should use a 0 in all.

You can find more information about FPDF on your website .

    
answered by 22.08.2017 / 07:58
source