IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[FPDF] plusieur code barre dans un tableau fpdf


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre du Club
    Inscrit en
    Février 2007
    Messages
    69
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 69
    Points : 53
    Points
    53
    Par défaut [FPDF] plusieur code barre dans un tableau fpdf
    bonjour

    je n'arrive pas a intégrer le code barre ( code 39) d'un article dans un tableau rempli par une lecture dans une bdd sql

    j'arrive a remplir mon tableau

    a mettre un code barre en même temps, a la positionner sur ma page un peu ou je veux mais comment les insérez dans mon tableau???

    merci pour votre aide


    code du tableau:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?Php
     
     
    $host_name = "localhost";
    $database = "gestion_consommables"; // Change your database nae
    $username = "***";          // Your database user id 
    $password = "****";          // Your password
     
    //////// Do not Edit below /////////
    try {
    $dbo = new PDO('mysql:host='.$host_name.';dbname='.$database, $username, $password);
    } catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
    }
     
     
    $count="SELECT * FROM ref_epi ";
    	$le_service=0;
    	if (isset($_GET['service'])) {
    		if ($_GET['service']==1){$count="SELECT * FROM ref_epi where service_1='1'";$le_service=1;}
    		if ($_GET['service']==2){$count="SELECT * FROM ref_epi where service_2='1'";$le_service=2;}
    		if ($_GET['service']==3){$count="SELECT * FROM ref_epi where service_3='1'";$le_service=3;}
     
    	}
     
     
    require('code39.php');
     
     
    $pdf = new PDF_Code39();
    $pdf->AddPage();
     
    $pdf->Code39(0,0,'CODE 39',1,10); // code barre a mettre dans une cellule
     
     
    $width_cell=array(20,100,5,5,5);
    $pdf->SetFont('Arial','B',7);
     
    $pdf->SetFillColor(193,229,252); // Background color of header 
    // Header starts /// 
    $pdf->Cell($width_cell[0],10,'REFERENCE',1,0,'C',true); // First header column 
    $pdf->Cell($width_cell[1],10,'DESIGNATION',1,0,'L',true); // Second header column
    $pdf->Cell($width_cell[2],10,'CODE BARRE',1,1,'C',true); // Third header column 
     
     
    //// header ends ///////
     
    $pdf->SetFont('Arial','',6);
    $pdf->SetFillColor(235,236,236); // Background color of header 
    $fill=false; // to give alternate background fill color to rows 
     
    /// each record is one row  ///
    foreach ($dbo->query($count) as $row) {
    $pdf->Cell($width_cell[0],10,$row['reference'],1,0,'C',$fill);
    $pdf->Cell($width_cell[1],10,$row['designation'],1,0,'L',$fill);
    $pdf->Cell($width_cell[2],10,'e',1,1,'C',$fill); // mettre le code barre dans cette cellule
     
    $fill = !$fill; // to give alternate background fill  color to rows
    }
    /// end of records /// 
     
    $pdf->Output();
     
     
    ?>
    la fonction utilisé pour le code barre 39
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    <?php
     
    require('fpdf.php');
     
     
    class PDF_Code39 extends FPDF
    {
    function Code39($xpos, $ypos, $code, $baseline=0.5, $height=5){
     
    	$wide = $baseline;
    	$narrow = $baseline / 3 ; 
    	$gap = $narrow;
     
    	$barChar['0'] = 'nnnwwnwnn';
    	$barChar['1'] = 'wnnwnnnnw';
    	$barChar['2'] = 'nnwwnnnnw';
    	$barChar['3'] = 'wnwwnnnnn';
    	$barChar['4'] = 'nnnwwnnnw';
    	$barChar['5'] = 'wnnwwnnnn';
    	$barChar['6'] = 'nnwwwnnnn';
    	$barChar['7'] = 'nnnwnnwnw';
    	$barChar['8'] = 'wnnwnnwnn';
    	$barChar['9'] = 'nnwwnnwnn';
    	$barChar['A'] = 'wnnnnwnnw';
    	$barChar['B'] = 'nnwnnwnnw';
    	$barChar['C'] = 'wnwnnwnnn';
    	$barChar['D'] = 'nnnnwwnnw';
    	$barChar['E'] = 'wnnnwwnnn';
    	$barChar['F'] = 'nnwnwwnnn';
    	$barChar['G'] = 'nnnnnwwnw';
    	$barChar['H'] = 'wnnnnwwnn';
    	$barChar['I'] = 'nnwnnwwnn';
    	$barChar['J'] = 'nnnnwwwnn';
    	$barChar['K'] = 'wnnnnnnww';
    	$barChar['L'] = 'nnwnnnnww';
    	$barChar['M'] = 'wnwnnnnwn';
    	$barChar['N'] = 'nnnnwnnww';
    	$barChar['O'] = 'wnnnwnnwn'; 
    	$barChar['P'] = 'nnwnwnnwn';
    	$barChar['Q'] = 'nnnnnnwww';
    	$barChar['R'] = 'wnnnnnwwn';
    	$barChar['S'] = 'nnwnnnwwn';
    	$barChar['T'] = 'nnnnwnwwn';
    	$barChar['U'] = 'wwnnnnnnw';
    	$barChar['V'] = 'nwwnnnnnw';
    	$barChar['W'] = 'wwwnnnnnn';
    	$barChar['X'] = 'nwnnwnnnw';
    	$barChar['Y'] = 'wwnnwnnnn';
    	$barChar['Z'] = 'nwwnwnnnn';
    	$barChar['-'] = 'nwnnnnwnw';
    	$barChar['.'] = 'wwnnnnwnn';
    	$barChar[' '] = 'nwwnnnwnn';
    	$barChar['*'] = 'nwnnwnwnn';
    	$barChar['$'] = 'nwnwnwnnn';
    	$barChar['/'] = 'nwnwnnnwn';
    	$barChar['+'] = 'nwnnnwnwn';
    	$barChar['%'] = 'nnnwnwnwn';
     
    	$this->SetFont('Arial','',10);
    	$this->Text($xpos, $ypos + $height + 4, $code);
    	$this->SetFillColor(0);
     
    	$code = '*'.strtoupper($code).'*';
    	for($i=0; $i<strlen($code); $i++){
    		$char = $code[$i];
    		if(!isset($barChar[$char])){
    			$this->Error('Invalid character in barcode: '.$char);
    		}
    		$seq = $barChar[$char];
    		for($bar=0; $bar<9; $bar++){
    			if($seq[$bar] == 'n'){
    				$lineWidth = $narrow;
    			}else{
    				$lineWidth = $wide;
    			}
    			if($bar % 2 == 0){
    				$this->Rect($xpos, $ypos, $lineWidth, $height, 'F');
    			}
    			$xpos += $lineWidth;
    		}
    		$xpos += $gap;
    	}
    }
    }
     
    ?>

  2. #2
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Tu peux faire comme ça.

    1 - mettre le set font sur chaque ligne du tableau car Code39 change la police et la taille.
    2 - récupérer les coordonnées x et y courantes pour les affecter au positionnement du code à barre.

    Ensuite à toi d'adapter.


    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?Php
    $query   = array();
    $query[] = array('reference'=>'12345','designation'=>'Ascorbate de potassium','cb'=>'12345');
    $query[] = array('reference'=>'23456','designation'=>'Plutonium expanse','cb'=>'23456');
    $query[] = array('reference'=>'34567','designation'=>'Nitrite de Nitrate','cb'=>'34567');require('code39.php');
     
     
    $pdf = new PDF_Code39();
    $pdf->AddPage(); 
     
    $width_cell=array(20,100,40,5,5);
    $pdf->SetFont('Arial','B',7);
     
    $pdf->SetFillColor(193,229,252); // Background color of header 
    // Header starts /// 
    $pdf->Cell($width_cell[0],10,'REFERENCE',1,0,'C',true); // First header column 
    $pdf->Cell($width_cell[1],10,'DESIGNATION',1,0,'L',true); // Second header column
    $pdf->Cell($width_cell[2],10,'CODE BARRE',1,1,'C',true); // Third header column 
     
     
    //// header ends ///////
     
    $pdf->SetFont('Arial','',5);
    $pdf->SetFillColor(235,236,236); // Background color of header 
    $fill=false; // to give alternate background fill color to rows 
     
    /// each record is one row  ///
    foreach ($query as $row) {
    $pdf->SetFont('Arial','',6); // mettre le setfont ici car Code39 change la police et sa taille
    $pdf->Cell($width_cell[0],10,$row['reference'],1,0,'C',$fill);
    $pdf->Cell($width_cell[1],10,$row['designation'],1,0,'L',$fill);
    $x = $pdf->GetX(); // ramène la valeur courante de x
    $y = $pdf->GetY(); // ramène la valeur courante de y
    $pdf->Cell($width_cell[2],10,$pdf->Code39($x+2,$y+0.5,$row['cb'],1,5),1,1,'C',$fill); // mettre le code barre dans cette cellule
    //$fill = !$fill; // to give alternate background fill  color to rows
    }
    /// end of records /// 
     
    $pdf->Output();
     
     
    ?>

    Principales modifs du code :
    Nom : Capture20181013_002.JPG
Affichages : 997
Taille : 88,6 Ko

    Mon exemple donne :


    Nom : Capture20181013_001.JPG
Affichages : 869
Taille : 69,7 Ko
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  3. #3
    Membre du Club
    Inscrit en
    Février 2007
    Messages
    69
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 69
    Points : 53
    Points
    53
    Par défaut
    merci

    c'est super génial!!

    merci pour ton aide
    j'ai testé, j'avais un bug avec la couleur de fond alternante du tableau

    j'ai fais comme toi j'ai désactivé

    merci encore

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 17/06/2015, 15h40
  2. [WD19] Taille d'un code barre dans une cellule d'un tableau
    Par Nhaps dans le forum WinDev
    Réponses: 2
    Dernier message: 10/09/2014, 08h13
  3. Lire un code à barre dans un champ d'une table
    Par tleboukaka dans le forum Débuter
    Réponses: 1
    Dernier message: 05/09/2005, 15h15
  4. Création de codes barres dans un état access
    Par caporal dans le forum IHM
    Réponses: 5
    Dernier message: 15/11/2004, 14h13
  5. [CR] Utilisation de codes à barres dans crystal
    Par franck.cvitrans dans le forum SAP Crystal Reports
    Réponses: 4
    Dernier message: 29/06/2004, 08h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo