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

Langage PHP Discussion :

utilisation de la méthode MultiCell fpdf


Sujet :

Langage PHP

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2020
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Lozère (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Avril 2020
    Messages : 12
    Points : 9
    Points
    9
    Par défaut utilisation de la méthode MultiCell fpdf
    Bonjour à tous
    J'essaie de générer un pdf avec fpdf.
    Comment utiliser la méthode MultiCell pour régler la disposition de mes données dans mon tableau.
    Voici mon code php:
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
     <?php
    require('mysql_table.php');
    class PDF extends PDF_MySQL_Table
    {
    protected $ProcessingTable=false;
    protected $aCols=array();
    protected $TableX;
    protected $HeaderColor;
    protected $RowColors;
    protected $ColorIndex;
    function Header()
    {
        // Print the table header if necessary
        //if($this->ProcessingTable)
         //   $this->TableHeader();
        // Title
        $this->SetFont('Arial','',14);
        // Logo
    $this->Image('logo.png',160,15,30);
    // Saut de ligne
    $this->Ln(10);
    $this->y0 = $this->GetY();
        // Ensure table header is printed
        parent::Header();
    }
    function TableHeader()
    {
        $this->SetFont('Arial','B',12);
        $this->SetX($this->TableX);
        $fill=!empty($this->HeaderColor);
        if($fill)
            $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
        foreach($this->aCols as $col)
            $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
        $this->Ln();
    }
     
    function Row($data)
    {
        $this->SetX($this->TableX);
        $ci=$this->ColorIndex;
        $fill=!empty($this->RowColors[$ci]);
        if($fill)
            $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
        foreach($this->aCols as $col)
            $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
        $this->Ln();
        $this->ColorIndex=1-$ci;
    }
     
    function CalcWidths($width, $align)
    {
        // Compute the widths of the columns
        $TableWidth=0;
        foreach($this->aCols as $i=>$col)
        {
            $w=$col['w'];
            if($w==-1)
                $w=$width/count($this->aCols);
            elseif(substr($w,-1)=='%')
                $w=$w/100*$width;
            $this->aCols[$i]['w']=$w;
            $TableWidth+=$w;
        }
        // Compute the abscissa of the table
        if($align=='C')
            $this->TableX=max(($this->w-$TableWidth)/2,0);
        elseif($align=='R')
            $this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
        else
            $this->TableX=$this->lMargin;
    }
     
    function AddCol($field=-1, $width=-1, $caption='', $align='L')
    {
        // Add a column to the table
        if($field==-1)
            $field=count($this->aCols);
        $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
    }
     
    function Table($link, $query, $prop=array())
    {
        // Execute query
        $res=mysqli_query($link,$query) or die('Error: '.mysqli_error($link)."<br>Query: $query");
        // Add all columns if none was specified
        if(count($this->aCols)==0)
        {
            $nb=mysqli_num_fields($res);
            for($i=0;$i<$nb;$i++)
                $this->AddCol();
        }
        // Retrieve column names when not specified
        foreach($this->aCols as $i=>$col)
        {
            if($col['c']=='')
            {
                if(is_string($col['f']))
                    $this->aCols[$i]['c']=ucfirst($col['f']);
                else
                    $this->aCols[$i]['c']=ucfirst(mysqli_fetch_field_direct($res,$col['f'])->name);
            }
        }
        // Handle properties
        if(!isset($prop['width']))
            $prop['width']=0;
        if($prop['width']==0)
            $prop['width']=$this->w-$this->lMargin-$this->rMargin;
        if(!isset($prop['align']))
            $prop['align']='C';
        if(!isset($prop['padding']))
            $prop['padding']=$this->cMargin;
        $cMargin=$this->cMargin;
        $this->cMargin=$prop['padding'];
        if(!isset($prop['HeaderColor']))
            $prop['HeaderColor']=array();
        $this->HeaderColor=$prop['HeaderColor'];
        if(!isset($prop['color1']))
            $prop['color1']=array();
        if(!isset($prop['color2']))
            $prop['color2']=array();
        $this->RowColors=array($prop['color1'],$prop['color2']);
        // Compute column widths
        $this->CalcWidths($prop['width'],$prop['align']);
        // Print header
        $this->TableHeader();
        // Print rows
        $this->SetFont('Arial','',11);
        $this->ColorIndex=0;
        $this->ProcessingTable=true;
        while($row=mysqli_fetch_array($res))
            $this->Row($row);
        $this->ProcessingTable=false;
        $this->cMargin=$cMargin;
        $this->aCols=array();
    }
    }
     
    // Connect to database
    $link = mysqli_connect('localhost','test','test_','test');
     
    $pdf = new PDF();
    $pdf->AddPage();
    // First table: output all columns
    $pdf->Table($link,'SELECT date,details,sender,content,amount,check_status FROM int_transfer WHERE user_id = 142 UNION SELECT date,details,sender,content,amount,check_status FROM tran_acct WHERE user_id = 142 UNION SELECT date,details,sender,content,amount,check_status FROM int_transfer_admin WHERE user_id = 142 ORDER BY date DESC');
    $pdf->AddPage();
    // Second table: specify 3 columns
    $pdf->AddCol('date',25,'','C');
    $pdf->AddCol('details',20,'Type');
    $pdf->AddCol('sender',30,'Beneficiary','R'); 
    $pdf->AddCol('content',60,'Details ','C');
    $pdf->AddCol('amount',20,'Amount');
    $pdf->AddCol('check_status',30,'Status','C');
     
    $prop = array('HeaderColor'=>array(255,150,100),
                'color1'=>array(210,245,255),
                'color2'=>array(255,255,210),
                'padding'=>2);
    $pdf->Table($link,'SELECT date,details,sender,content,amount,check_status FROM int_transfer WHERE user_id = 142 UNION SELECT date,details,sender,content,amount,check_status FROM tran_acct WHERE user_id = 142 UNION SELECT date,details,sender,content,amount,check_status FROM int_transfer_admin WHERE user_id = 142 ORDER BY date DESC',$prop);
    $pdf->Output();
     
    ?>
    Ce que j obtiens comme résultat pdf


    Je vous prie de bien vouloir m’aider.
    Merci

  2. #2
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 221
    Points : 15 512
    Points
    15 512
    Par défaut
    qu'est ce que vous souhaitez obtenir comme résultat ?
    montrez-nous une image d'exemple de ce que vous souhaitez.

Discussions similaires

  1. Réponses: 20
    Dernier message: 19/09/2006, 21h52
  2. [FPDF] Utilisation des librairies ezpdf et fpdf
    Par kirsoul dans le forum Bibliothèques et frameworks
    Réponses: 10
    Dernier message: 10/01/2006, 14h07
  3. Utilisation de la méthode FIND
    Par Jeannot45 dans le forum Access
    Réponses: 3
    Dernier message: 09/01/2006, 16h41
  4. [Ant] Utilisation de la méthode clone()
    Par Shabata dans le forum ANT
    Réponses: 1
    Dernier message: 01/12/2005, 16h01
  5. [Select()/Focus()] Pb dans l'utilisation de ces méthodes
    Par Kylen dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 23/06/2005, 15h54

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