How to take a line break when the end of the margin is reached with FPDF

1

I am generating a PDF document with the FPDF library and I could generate it, but I really do not know how to make it jump to the next line when I reach the end of the margin.

The code I have puts the elements next to each other with a separation, the first three are fine but the problem is with the fourth one since that should go down to the next line and so on.

PHP Code

<?php
    include 'fpdf/fpdf.php';
    $pdf = new FPDF('P','mm','A4');
    $pdf->SetMargins(15,10,15);
    $pdf->SetAutoPageBreak(true, 10);
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf -> Cell(50,10,'sebastian',1,1,'C');
    $x = $pdf->GetX();
    $y = $pdf->GetY(); 
    $y=$y-10;
    for ($i = 1; $i<=3; $i++){
        $pdf->SetXY($x-150,$y);
        $x = $pdf->GetX();
        $y = $pdf->GetY();
        $pdf -> Cell(50,10,"SEBASTIAN",1,1,'C');
    }
    $pdf->Output();
?>

Result

I would greatly appreciate your help.

    
asked by Familia Valencia Hdz 06.02.2018 в 20:58
source

1 answer

0

I already found the solution to my problem, I do not know if it is the most optimal, but I did so, I accept suggestions.

<?php
	include 'fpdf/fpdf.php';
	include '../php/conex.php';
	$sql = "SELECT user, centros_salidas.nombre AS centro, territorios.nombre AS territorio, fecha_ini, fecha_fin FROM territorio_predicado, hermanos, centros_salidas, territorios WHERE territorio_predicado.cedula = hermanos.cedula AND territorio_predicado.id_centro = centros_salidas.id_centro AND territorio_predicado.id_territorio = territorios.id_territorio";
	$resultado = mysqli_query($con,$sql);
	$pdf = new FPDF('P','mm','A4');
	$pdf->SetAutoPageBreak(false);
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',16);
	$pdf->SetXY(10,10);
	$pdf -> Cell(35,10,'sebastian',1,1,'C');
	$x = 10;
	$y = 10;
	$ap = $pdf->GetPageHeight();
	for ($i = 1; $i<=100; $i++){
		if($x >= 170)
		{
			$y = $y + 15;
			$x = 10;
			$pdf->SetXY($x,$y);
		}else{
			$pdf->SetXY($x+40,$y);
		}
		$x = $pdf->GetX();
		if($y == 295)
		{
			$y = 10;
			$x = 10;
			$pdf->SetXY($x,$y);
			$pdf->AddPage();
		}
		$pdf -> Cell(35,10,"SEBASTIAN",1,1,'C');
	}
	$pdf->Output();
?>

    
answered by 07.02.2018 / 14:14
source