<?php
require "fpdf.php";
 // Insert a logo in the top-left corner at 300 dpi
class myPDF extends FPDF
{
    function header(){
        // Logo
    $this->Image('logo.png',50,6,40);
    $this->Image('logo.png',200,6,40);   
    $this->Cell(30,5,'',0,1,'C');
       $this->Ln();
   }
function footer(){   
    $this->SetY(-15);
    $this->SetFont('Arial','',8);
    $this->Cell(0,10,'Page'.$this->pageNo().'/{nb}',0,0,'L');
    }
function headerTable(){
    $this->SetFont('Times','',10);   
    $this->Ln();   
    }
    function viewTable($db){
        $this->SetFont('Times','',10);
         $db = New PDO('mysql:host=xxxxxx;dbname=xxxxxx',xxxxxx,xxxxxxxx);
        $stmt=$db->query ('SELECT *FROM Ordini ORDER BY id DESC LIMIT 1');
 while ($data=$stmt->fetch(PDO::FETCH_OBJ)){
     $this->SetFont('Times','',15);
        $this->Cell(10,10,'N.',1,0,'C');
        $this->SetFont('Times','',30);
        $this->Cell(15,10,$data->id,1,0,'C');
        $this->SetFont('Times','',15);
                        $this->Cell(125,10,'',0,0,'L');
                        $this->Cell(10,10,'N.',1,0,'C');
        $this->SetFont('Times','',30);
        $this->Cell(15,10,$data->id,1,0,'C');           
      $this->Cell(20,10,'',0,1,'L');   
        $this->SetFont('Times','',12);       
        $this->Cell(50,10,'nome',0,0,'L');
        $this->Cell(20,10,'',0,0,'L');
         $this->Cell(50,10,'cognome',0,0,'R');
              $this->Cell(30,10,'',0,0,'L');
$this->Cell(50,10,'nome',0,0,'L');
        $this->Cell(20,10,'',0,0,'L');
         $this->Cell(50,10,'cognome',0,1,'R');                 
         $this->SetFont('Times','',16);
        $this->Cell(50,10,$data->nome,1,0,'L');
        $this->Cell(20,10,'',0,0,'L');
        $this->Cell(50,10,$data->cognome,1,0,'L');
                      $this->Cell(30,10,'',0,0,'L');       
                       $this->SetFont('Times','',16);
        $this->Cell(50,10,$data->nome,1,0,'L');
        $this->Cell(20,10,'',0,0,'L');
        $this->Cell(50,10,$data->cognome,1,1,'L');       
        $this->SetFont('Times','',12);
        $this->Cell(120,5,'recapito',0,0,'C');
                              $this->Cell(30,10,'',0,0,'L');
$this->Cell(120,5,'recapito',0,1,'C');       
        $this->SetFont('Times','',16);
        $this->Cell(120,10,$data->recapito,1,0,'C');
                                      $this->Cell(30,10,'',0,0,'L');
$this->Cell(120,10,$data->recapito,1,1,'C');
        $this->SetFont('Times','',12);
        $this->Cell(120,5,'data Ritiro',0,0,'C');
                                              $this->Cell(30,10,'',0,0,'L');
        $this->Cell(120,5,'data Ritiro',0,1,'C');
        $this->SetFont('Times','',16);
        $this->Cell(120,10,$data->data_ritiro,1,0,'C');
                                                      $this->Cell(30,10,'',0,0,'L');
        $this->Cell(120,10,$data->data_ritiro,1,1,'C');
        $this->Cell(20,5,'',0,0,'L');
        $this->Cell(30,5,'',0,0,'L');
        $this->Cell(20,5,'',0,1,'L');
        $this->SetFont('Times','',12);
        $this->Cell(110,10,'Descrizione',1,0,'L');                                                                 
        $this->Cell(10,10,'Q.ta',1,0,'C');
         $this->Cell(30,10,'',0,0,'L');
        $this->Cell(110,10,'Descrizione',1,0,'L');
        $this->Cell(10,10,'Q.ta',1,1,'C');
        $this->SetFont('Times','',16);
        $this->Cell(110,10,$data->descrizione1,1,0,'L');
        $this->Cell(10,10,$data->quantita1,1,0,'C');
        $this->Cell(30,10,'',0,0,'L');
        $this->Cell(110,10,$data->descrizione1,1,0,'L');
        $this->Cell(10,10,$data->quantita1,1,1,'C');
        $this->Cell(110,10,$data->descrizione2,1,0,'L');
        $this->Cell(10,10,$data->quantita2,1,0,'C');
         $this->Cell(30,10,'',0,0,'L');
        $this->Cell(110,10,$data->descrizione2,1,0,'L');
        $this->Cell(10,10,$data->quantita2,1,1,'C');
        $this->Cell(110,10,$data->descrizione3,1,0,'L');
        $this->Cell(10,10,$data->quantita3,1,0,'C');
        $this->Cell(30,10,'',0,0,'L');
        $this->Cell(110,10,$data->descrizione3,1,0,'L');
        $this->Cell(10,10,$data->quantita3,1,1,'C')
        $this->Cell(110,10,$data->descrizione4,1,0,'L');
        $this->Cell(10,10,$data->quantita4,1,0,'C');
                $this->Cell(30,10,'',0,0,'L');
        $this->Cell(110,10,$data->descrizione4,1,0,'L');
        $this->Cell(10,10,$data->quantita4,1,1,'C');   
         $this->Cell(30,5,'',0,1,'L');       
        $this->Cell(120,10,'Note',1,0,'C');
                 $this->Cell(30,10,'',0,0,'L');
        $this->Cell(120,10,'Note',1,1,'C');       
        $this->Cell(120,10,$data->Note,1,0,'L');
                         $this->Cell(30,10,'',0,0,'L');
        $this->Cell(120,10,$data->Note,1,1,'L');
        $this->SetFont('Times','',8);                                         
                 $this->Ln();
    }
    }
}
$pdf = new myPDF();
$pdf->Aliasnbpages();
$pdf->Addpage('L','A4','0');
$pdf->headerTable();
$pdf->viewTable($db);
$pdf->Output();