Foreach in the FPDI repeats the data in the same place

Asked

Viewed 16 times

0

I dynamically send to this file via controller the data in an array called $vaccines, I am using Import Autoload for this reason. It turns out that the information is being printed in the same place:

<?php

use setasign\Fpdi\Fpdi;

require_once 'vendor/autoload.php';

$pdf = new Fpdi();

$pdf->AddPage('L');
$pdf->setSourceFile("report/cartaoFront.pdf");
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 5, 5, 290);

/**
 * Dados animal
*/


$pdf->addPage('L');
$pdf->setSourceFile("report/cartaoVerso.pdf");

$tplId = $pdf->importPage(1);
$pdf->useTemplate($tplId, 5, 5, 290);

$pdf->SetFont('Arial','',10);

foreach ($vacinas as $item) 
{
    
        $pdf->SetTextColor(255, 0, 0);
        
        // Nome Vacina
        $pdf->SetXY(12, 35);
        $pdf->Cell(5,0,$item['titulo_vacina'],0,1,"C");

        // Nome Méd Veterinário
        $pdf->SetXY(68, 35);
        $pdf->Cell(5,0,utf8_decode($item['nome_veterinario']),0,1,"C");

    
}

$pdf->Output();  

inserir a descrição da imagem aqui And I need you to enter the information below each one. I tried using $pdf->gety() * 2 but it spaces a lot, also tried using for only it ends up printing 2 or how many data return in the same field.

What I want to solve with this doubt: Make the foreach not repeat the data in the same location but each interaction increment (+ the value of the previous y)

I tried so: $pdf->SetXY(68, 35 + ($pdf->getY(); but it didn’t work either.

1 answer

0


Solution:

    $pdf->SetXY(12, 25 + ($pdf->getY()));
    $pdf->Cell(5,0,$item['titulo_vacina'],0,1,"C");

    
    $pdf->SetXY(68, ($pdf->getY()));
    $pdf->Cell(5,0,utf8_decode($item['nome_veterinario']),0,1,"C");

Instead of adding it to gety() with other values, I just put it neat that was below each other respecting the order of proportion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.