How to create a new page with a format already established in FPDF?

1

I have an application already prepared in which one of its modules is to generate PDF reports, the report is generated excellent, the detail is that I need every 20 records to generate a new page of this report but it is generated in white and this should not be the case. How can I make this new page with its header and structure like the previous page of the document? I am a computer student and since I am acquiring knowledge, I will appreciate your help please. The library that I am using is FPDF this is the code:

<?php

require "pdf/fpdf.php";

class PDF extends FPDF
{
}


//declaramos la hoja

$pdf= new PDF ('L','mm',array(500, 500));
$pdf->SetMargins(10,5);
$pdf->SetTopMargin(2);
$pdf->SetLeftMargin(10);
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(true,155);
$pdf->AddPage();


//Datos del titulo


$pdf->SetTextColor(0x00, 0x00, 0x00);
$pdf->SetFont("Arial", "", 9);
$pdf->Image('logo.png' , 390,20, 35 , 38,'png','');
$pdf->Cell(0, 20, '', 0, 1, 'C');
$pdf->Cell(0, 5, 'REPUBLICA BOLIVARIANA DE VENEZUELA', 0, 1, 'C');
$pdf->Cell(0, 5, 'AGENCIA AUTOMOTRIZ ALLCARS', 0, 1, 'C');
$pdf->ln();
$pdf->SetFont("Arial", "", 12);
$pdf->Cell(0, 5, 'INVENTARIO FISICO', 0, 1, 'C');
$pdf->Cell(0, 5, 'AUTOS:', 0, 1, 'C');
$pdf->Cell(0, 5, 'FECHA:', 0, 1, 'C');


//Datos de conexion

mysql_connect("localhost", "USER", "PASSWORD");
mysql_select_db("BASE_DE_DATOS");

//FIN DE DATOS DE CONEXION

$sql="SELECT * FROM tabla";
$rec= mysql_query($sql);

while ($row=mysql_fetch_array($rec))
{
$pdf->Cell(0,5, $row['fecha'], 0, 0, 'C');
}

$pdf->ln();

$pdf->Ln();
$pdf->SetFontSize(8);

$pdf->SetTextColor(0x00, 0x00, 0x00);
$pdf->SetFont("Arial", "", 8);
$pdf->Cell(265, 5, '1.- CLIENTE:', 1, 0, 'C');
$pdf->Ln();

$pdf->Cell(40, 5, 'CEDULA DE IDENTIDAD', 1, 0, 'C');
$pdf->Cell(120, 5, 'APELLIDOS Y NOMBRES', 1, 0, 'C');
$pdf->Cell(20, 5, 'DIRECCION', 1, 0, 'C');
$pdf->Cell(85, 5, 'CEDULA', 1, 0, 'C');


$pdf->SetFontSize(9);

$sql="SELECT * FROM encabezado";
$rec= mysql_query($sql);

while ($row=mysql_fetch_array($rec))
{
$pdf->Cell(80, 10, $row['direccion_li'], 1, 0, 'C');
$pdf->Cell(30, 10, $row['cod_ut'], 1, 0, 'C');
$pdf->Cell(90, 10, $row['division'], 1, 0, 'C');
$pdf->Cell(0, 5, '', 0, 0, 'C');
}



**//
// AQUI NECESITO QUE SIGA CON EL FORMATO YA ESTABLECIDO EN UNA NUEVA HOJA**
$pdf->Ln();
$pdf->SetFontSize(9);

$sql="SELECT * FROM encabezado";
$rec= mysql_query($sql);

while ($row=mysql_fetch_array($rec))
{

$pdf->Cell(40, 5, $row['ced'], 1, 0, 'C');
$pdf->Cell(120, 5, $row['nombres'], 1, 0, 'C');
$pdf->Cell(20, 5, $row['codigo'], 1, 0, 'C');
$pdf->Cell(85, 5, $row['uep'], 1, 0, 'C');


}
**//
// HASTA AQUI**




$pdf->Ln();


$pdf->SetFontSize(9);
$pdf->Cell(170, 5, 'DIRECTOR', 0, 0, 'C');
$pdf->Cell(170, 5, 'CLIENTE', 0, 0, 'C');
$pdf->Ln();
$pdf->Ln();
$pdf->Cell(170, 5, 'FIRMA', 0, 0, 'C');
$pdf->Cell(170, 5, 'FIRMA', 0, 0, 'C');


$pdf->Output(/*$Archivo, $tipo_output*/);
//$pdf->Output("Contrato_".$per_Rut."-".$per_DV.".pdf", "D");
?>

in the part that you specify as a comment is the one that shows me the list of the data stored in the database before, what I need is that each time a new page is generated, the format as (logo, header, date, lower signatures, etc) already appears, just keep showing me results of the list if there are any

    
asked by Anto J 05.05.2016 в 22:42
source

1 answer

2

I'll give you an example:

public function LineItems() {
        $datos = $this->listaItemsDetalle(); 
        $header = array("REPUBLICA BOLIVARIANA DE VENEZUELA", "AGENCIA AUTOMOTRIZ","INVENTARIO FISICO","CANT.", "AUTOS");
        $this->SetDataFont();
        $this->AddPage();
        $w = array(10, 40,90, 15, 20);

    for($i = 0; $i < count($header); $i++) {
        $this->SetFillColor(192,192,192);
        $this->SetTextColor(0,0,0);
        $this->SetFontSize(10);
        $this->Cell($w[$i], 7, $header[$i], 1, 0, 'L','true');
    }

    $this->Ln();
    $x = $this->GetX();
    $y = $this->GetY();
    $i = 0;
    //////////////la razon indica cuantos items seran visibles en cada hoja.
    $razon=30;

    while ($row = mysql_fetch_row($datos)) {
        //print_r('<pre>');
        //print_r($row);
        $data[] = array(++$i, $row[5],$row[4], $row[2], $row[3]);
    }

    if (!isset($data)) {
        $data[] = null;
     }else{
        $j=$i;
        foreach($data as $row)
        {   
            if($i>=($j+$razon)){
                $this->AddPage();
                $this->SetFont('Arial', 'B', 3);
                $this->setTextFont(true);
                $header = array("REPUBLICA BOLIVARIANA DE VENEZUELA", "AGENCIA AUTOMOTRIZ","INVENTARIO FISICO","CANT.", "AUTOS");
                //$this->SetDataFont();
                $this->setTextFont(false);
                $this->SetDataFont();
                $w = array(10, 40, 90,  15, 20);

                for($i = 0; $i < count($header); $i++) {
                $this->SetFillColor(192,192,192);
                $this->SetTextColor(0, 0, 0);
                $this->SetFontSize(10);
                $this->Cell($w[$i], 7, $header[$i], 1, 0, 'L','true');
            }

            $this->Ln();
            $j=$i;
            }
                $this->SetFontSize(8);
                $this->SetTextColor(0, 0, 0);
                $y1 = $this->GetY();

                $this->MultiCell($w[0], 6, $row[0], 'R');
                $y2 = $this->GetY();
                $yH = $y2 - $y1;

                $this->SetXY($x + $w[0], $this->GetY() - $yH);

                $this->Cell($w[1],$yH,$row[1],0, 0, 'L');
                $this->Cell($w[2],$yH,$row[2],0, 0, 'L');
                $this->Cell($w[3],$yH,$row[3],0, 0, 'R');
                $this->Cell($w[4],$yH,$row[4],0, 0, 'L');
                //$this->Cell($w[5],$yH,$row[5],'LRB', 0, 'C');

            $this->Ln();
            $i++;
        }
    }

    $this->Ln(10);

}

The important thing is the value of $razon , every time you show 30 lines create a new page and reload what is in the header (which in your case would be the header you want to show), sorry but I had a lot of time to do it on yours. I hope you serve the example.

    
answered by 16.05.2016 / 15:17
source