1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| <?
session_start();
include("config.php");
include("fpdf.php");
class PDF extends FPDF
{
//Tableau coloré
function ExportTableau($header,$data)
{
//Couleurs, épaisseur du trait et police grasse
$this->SetFillColor(150,180,255); //fond des entetes de colonnes
$this->SetTextColor(0); //couleur du texte des entetes des colonnes
$this->SetDrawColor(0); // couleur des bordures
$this->SetLineWidth(.3); //epaisseur des traits
$this->SetFont('','B');
//En-tête
$w=array(35,20,50,20,45,20,27,27,45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
$this->Ln();
//Restauration des couleurs et de la police
$this->SetFillColor(224,235,255); //couleur du fond des cases
$this->SetTextColor(0); //couleur du texte des cases
$this->SetFont('');
//Données
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'L',$fill);
$this->Cell($w[4],6,$row[4],'LR',0,'L',$fill);
$this->Cell($w[5],6,$row[5],'LR',0,'L',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
//Requete SQL
$query = "SELECT photos, reference, nom_produit, collisage, code_barre, prix FROM produit";
$result = mysql_query($query) or die ('Erreur SQL !<br />' . $query . '<br />' . mysql_error());
//Boucle sur les resultats
$data = array();
while($col = mysql_fetch_array($result))
{
array($col);
$data[] = $col;
}
//Creation pdf
$pdf=new PDF('P','mm','A4');
//Titres des colonnes
$header=array('Photo','Reference','Nom du Produit','Collisage','Code barre','Prix');
//Tableau
$pdf->SetFont('Arial','',8);
$pdf->SetMargins(5,5);
$pdf->AddPage();
$pdf->ExportTableau($header,$data);
$pdf->Output('liste_produit.pdf','I');
?> |
Partager