0
I’m having trouble making a pagination.
It receives the data of the report in array format, then I have to do a foreach to scan the data, it happens that I am doing it within 2 for, and the data keep repeating, as I solve already tried to use some break, but it does not work ?
namespace Helpers;
require_once 'Fpdf/fpdf.php';
require_once 'FormataData.php';
require_once 'C:xampp/htdocs/pim_dev/DAO/EstoqueDAO.php';
use \FPDF;
class RelatorioPorEntrada {
public function gerar($dataOne, $dataTwo, $dados)
{
$logo = "c:xampp/htdocs/pim_dev/content/img/relat4.png";
$data = date('j/m/Y');
$por_pagina = 3;
$row = count($dados);
$paginas = ceil($row/$por_pagina);
$pdf = new FPDF("P", "cm", "A4");
$linha_atual = 0;
$inicio = 0;
for($x=1; $x<=$paginas; $x++)
{
$inicio = $linha_atual;
$fim = $linha_atual + $por_pagina;
if($fim > $row) $fim = $row;
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont("arial");
$pdf->Image($logo, 0,0);
$pdf->SetTitle("Relatorio");
$pdf->Ln(1);
$pdf->SetFontSize(14);
$pdf->Cell(0,3, utf8_decode("Relatório Mensal"),0,0,"C");
$pdf->SetFontSize(10);
$pdf->Cell(0, 5, utf8_decode("Página $x de $paginas"),0, 0, "R");
$pdf->Ln(1);
$pdf->Cell(0,3, "Data:".$data,0,0,"E");
$pdf->Ln(1);
$dateFormat = new FormataData();
$novaDataone = $dateFormat->dateToBr($dataOne);
$novaDataTwo = $dateFormat->dateToBr($dataTwo);
$pdf->Cell(0,3,utf8_decode("Periodo:".$novaDataone." "."até ".$novaDataTwo),0,0,"E");
$pdf->SetFontSize(8);
$pdf->Ln(3);
$pdf->SetDrawColor(57,181,74);
$pdf->SetFillColor(57,181,74);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(1,1, "ID", 1,0,"C",true);
$pdf->Cell(3,1, "Produto", 1,0,"C",true);
$pdf->Cell(3,1, "Date de Entrada", 1,0,"C",true);
$pdf->Cell(2,1, utf8_decode("Valor Unitário"), 1,0,"C",true);
$pdf->Cell(2,1, "Quantidade", 1,0,"C",true);
$pdf->Cell(2,1, "Valor Total", 1,0,"C",true);
$pdf->SetTextColor(0,0,0);
for($i=$inicio; $i<$fim; $i++)
{
foreach($dados as $values)
{
$pdf->Ln(1);
$pdf->Cell(1,1, $dados[0], 1,0,"C");
$pdf->Cell(3,1, $dados[1], 1,0,"C");
$pdf->Cell(3,1, $dados[2], 1,0,"C");
$pdf->Cell(2,1, $dados[3], 1,0,"C");
$pdf->Cell(2,1, $dados[4], 1,0,"C");
$pdf->Cell(2,1, $dados[5], 1,0,"C");
}
$linha_atual++;
}
}
return $pdf->Output("relatorio.pdf", "I");
}
}
It would be interesting to add more content because this very vague your question
– Otto
It is a pagination before generating the pdf.
– alexjosesilva
My goal is to generate a pdf file without content breaks. When I start the text on a page I have to finish on this page.
– alexjosesilva
Edit the question by adding information
– Otto
I think I understand + or -. do you want it to be one table per page? If this is the case and in the Fpdf you can use CSS in the document configuration to generate the PDF, as in the DOMPDF example that "Transforms HTML and CSS into PDF", you could use the page-break-after and page-break-before property depending on your need. I hope that’s it.
– Marcus Italo