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] Générer graphique php en pdf


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Candidat au Club
    Inscrit en
    Mars 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 6
    Points : 2
    Points
    2
    Par défaut [FPDF] Générer graphique php en pdf
    Bonjour a tous, apres plusieurs recherches infructueuses, je viens demander de l'aide sur ce forum
    Voici mon probleme :
    A partir de php je genere un graphique dans mon application web et en fait je souhaiterai l'afficher dans un document pdf.
    Grace a fpdf j'arrive a generer un tableau avec mes données,mais je ne sais pas comment faire pour afficher le graphique.
    Si une ame charitable pouvait me filer un coup de main..
    Merci d'avance.
    Bonne aprem

  2. #2
    Membre éclairé
    Avatar de jc_cornic
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    623
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 623
    Points : 823
    Points
    823
    Par défaut
    Salut, si c'est un graphique avec des droites de type y=ax+b, alors, tu peux utiliser la librairie phpToPDF, sinon, je ne sais pas...

    ++
    JC

  3. #3
    Candidat au Club
    Inscrit en
    Mars 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Salut,
    merci pour ta reponse j'avais deja recuperer ce tuto en fait, mais mes graphs sont des histogrammes.. lol
    je continue mes recherches,peut etre faudrait il que je l'affiche d'abord dans une image,et ensuite generer l'image dans le pdf..

  4. #4
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 600
    Points
    12 600
    Par défaut
    Comment génère tu ton graphique à la base?

  5. #5
    Candidat au Club
    Inscrit en
    Mars 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    j'affiche l'image:

    header("Content-type: image/gif");

    imagegif($image);

  6. #6
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 600
    Points
    12 600
    Par défaut
    Donc tu utilises gd, pourquoi lors de la création de ton image , tu ne le mets pas dans un répertoire temporaire, le temps de générer ton pdf, puis tu le surprimes ?

  7. #7
    Candidat au Club
    Inscrit en
    Mars 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Euh...cad?

  8. #8
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 600
    Points
    12 600
    Par défaut
    Met moi ton code de la génération de ton image, pour voir ce que tu as déjà fais

  9. #9
    Candidat au Club
    Inscrit en
    Mars 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    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
    <?php
    $GraphiqueWidth=600;
    $GraphiqueHeight=400;
    $GraphiqueUnite=20;
    $GraphiquePolice=3;
     
     
    $GraphiqueDonnee=array($res1,$res2,$res3,$res4);
    $GraphiqueDonnee1=array($res5,$res6,$res7,$res8);
    $GraphiqueDonnee2=array($res9,$res10,$res11,$res12);
     
     
    /* Création de l'image */
     
    $image=imagecreate($GraphiqueWidth, $GraphiqueHeight);
     
    /* Définition des couleurs */
     
    $CouleurCorps=imagecolorallocate($image, 0xcc, 0xcc, 0xcc); 
    $CouleurTexte=imagecolorallocate($image, 0x00, 0x33, 0x33); 
    $CouleurRectangle=imagecolorallocate($image, 0xFF, 0x33, 0x33);
    $CouleurRectangle1=imagecolorallocate($image, 0xFF, 0x66, 0x66);
    $CouleurRectangle2=imagecolorallocate($image, 0xFF, 0x99, 0x99);
    $CouleurRectangle3=imagecolorallocate($image, 0xFF, 0xCC, 0xCC);
    $CouleurHache=imagecolorallocate($image, 0x00, 0x00, 0x00); 
     
    /* Définition de l'arrière-plan */
     
    imagefill($image, 0, 0, $CouleurCorps);
     
    /* Création des lignes verticales */
     
    $TexteHacheWidth=imagefontwidth($GraphiquePolice) * 3 + 1;
    imageline($image, $TexteHacheWidth, 0, $TexteHacheWidth, $GraphiqueHeight - 1, $CouleurHache);
     
    /* Création des lignes horizontales */
     
    for($i=0;$i<$GraphiqueHeight;$i += $GraphiqueHeight / 10){
     
    imagedashedline($image, 0, $i, $GraphiqueWidth -1, $i, $CouleurHache);
     
    /* Affichage du nom */
     
    imagestring($image, $GraphiquePolice, 0, $i, round(($GraphiqueHeight - $i)/$GraphiqueUnite), $CouleurTexte);
     
    }
     
    /* Création des lignes du bas du graphique */
     
    imageline($image, 0, $GraphiqueHeight -1, $GraphiqueWidth -1, $GraphiqueHeight -1, $CouleurHache);
     
    /* Création des barres */
     
    $BarreWidth0=(($GraphiqueWidth/4 - $TexteHacheWidth) / count($GraphiqueDonnee)) - 10;
    $BarreWidth1=(($GraphiqueWidth/4 - $TexteHacheWidth) / count($GraphiqueDonnee1)) - 10;
    $BarreWidth2=(($GraphiqueWidth/4 - $TexteHacheWidth) / count($GraphiqueDonnee2)) - 10;
     
     
    for($i=0;$i<count($GraphiqueDonnee);$i++){
     
    $BarreWidth = ($BarreWidth0 + $BarreWidth1 + $BarreWidth2);
     
    $BarreHautX= $TexteHacheWidth + (($i+1) *10) + ($i * $BarreWidth);
    $BarreBottomX= $BarreHautX + $BarreWidth;
    $BarreBottomY= $GraphiqueHeight -1;
     
    $BarreHautY= $BarreBottomY - ($GraphiqueDonnee[$i] * $GraphiqueUnite);
    $BarreHautY1= $BarreBottomY - ($GraphiqueDonnee1[$i] * $GraphiqueUnite);
    $BarreHautY2= $BarreBottomY - ($GraphiqueDonnee2[$i] * $GraphiqueUnite);
     
     
    imagefilledrectangle($image, $BarreHautX, $BarreHautY, $BarreBottomX-50, $BarreBottomY, $CouleurRectangle);
    imagefilledrectangle($image, $BarreHautX+17, $BarreHautY1, $BarreBottomX-33, $BarreBottomY, $CouleurRectangle1);
    imagefilledrectangle($image, $BarreHautX+34, $BarreHautY2, $BarreBottomX-16, $BarreBottomY, $CouleurRectangle2);
     
     
    $TexteX=$BarreHautX+ (($BarreBottomX - $BarreHautX)/2) - ( imagefontheight($GraphiquePolice) / 2);
    $TexteY=$BarreBottomY - $GraphiqueDonnee[$i]*$GraphiqueUnite;
    $TexteY1=$BarreBottomY - $GraphiqueDonnee1[$i]*$GraphiqueUnite;
    $TexteY2=$BarreBottomY - $GraphiqueDonnee2[$i]*$GraphiqueUnite;
     
     
    //affichage des infos barres
    if ($GraphiqueDonnee[$i]==0)
    {   
      imagestring($image, $GraphiquePolice, $TexteX-24, $TexteY-40, "$GraphiqueDonnee[$i]", $CouleurTexte);
     
    } 
    else
    {
      imagestring($image, $GraphiquePolice, $TexteX-24, $TexteY-15, "$GraphiqueDonnee[$i]", $CouleurTexte);
    }
    if ($GraphiqueDonnee1[$i]==0)
    {   
      imagestring($image, $GraphiquePolice, $TexteX-7, $TexteY1-40, "$GraphiqueDonnee1[$i]", $CouleurTexte);
     
    } 
    else
    {
      imagestring($image, $GraphiquePolice, $TexteX-7, $TexteY1-15, "$GraphiqueDonnee1[$i]", $CouleurTexte);
    }
    if ($GraphiqueDonnee2[$i]==0)
    {   
      imagestring($image, $GraphiquePolice, $TexteX+10, $TexteY2-40, "$GraphiqueDonnee2[$i]", $CouleurTexte);
     
    } 
    else
    {
      imagestring($image, $GraphiquePolice, $TexteX+10, $TexteY2-15, "$GraphiqueDonnee2[$i]", $CouleurTexte);
    }
     
    //affichage des circonstances
    imagestring($image, $GraphiquePolice, 45, 385, "$GraphiqueTexte[0]", $CouleurTexte);
    imagestring($image, $GraphiquePolice, 105, 385, "$GraphiqueTexte[1]", $CouleurTexte);
    imagestring($image, $GraphiquePolice, 185, 385, "$GraphiqueTexte[2]", $CouleurTexte);
    imagestring($image, $GraphiquePolice, 270, 385, "$GraphiqueTexte[3]", $CouleurTexte);
     
    //legende
    $Resultat=$GraphiqueDonnee[0]+$GraphiqueDonnee[1]+$GraphiqueDonnee[2]+$GraphiqueDonnee[3];
    $Resultat1=$GraphiqueDonnee1[0]+$GraphiqueDonnee1[1]+$GraphiqueDonnee1[2]+$GraphiqueDonnee1[3];
    $Resultat2=$GraphiqueDonnee2[0]+$GraphiqueDonnee2[1]+$GraphiqueDonnee2[2]+$GraphiqueDonnee2[3];
    imagefilledrectangle($image, 400, 25, 415, 10, $CouleurRectangle);
    imagestring($image, $GraphiquePolice, 420, 10, "".$Resultat, $CouleurTexte);
    imagefilledrectangle($image, 400, 40, 415, 25, $CouleurRectangle1);
    imagestring($image, $GraphiquePolice, 420, 25, " ".$Resultat1, $CouleurTexte);
    imagefilledrectangle($image, 400, 55, 415, 40, $CouleurRectangle2);
    imagestring($image, $GraphiquePolice, 420, 40, "".$Resultat2, $CouleurTexte);
     
    imagestring($image, $GraphiquePolice, 145, 80, "TITRE", $CouleurTexte);
    }
     
     
     
    header("Content-type: image/gif");
     
     
     
    imagegif($image);
    ?>

  10. #10
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 497
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 497
    Points : 12 600
    Points
    12 600
    Par défaut
    Essaye quelque chose comme çà

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    //header("Content-type: image/gif"); on affiche pas l'image
     
     
     
    imagegif($image,'/cheminRepertoire/NomFichier.gif'); //on l'enregistre
    Ca c'est une solution, mais si tu intègres ton code de génération d'image en même temps que celui de FPDF ceci devrais fonctionner

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $pdf->Image(imagegif($image),10,8,33);

  11. #11
    Candidat au Club
    Inscrit en
    Mars 2008
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 6
    Points : 2
    Points
    2
    Par défaut
    Apres quelques soucis c enfin reglé
    merci beaucoup pour ton aide vraiment sympa
    vive le php
    A bientot peut etre

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

Discussions similaires

  1. [JpGraph] générer graphiques php/excel
    Par Pr0pHeT dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 04/07/2014, 13h55
  2. [FPDF] Convertir page PHP/HTML > PDF
    Par arnaudperfect dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 05/02/2007, 02h31
  3. [FPDF] Générer un pdf ou un fichier openoffice avec le php
    Par Alain15 dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 28/06/2006, 03h10
  4. [FPDF] Générer de larges documents PDF
    Par LEK dans le forum Bibliothèques et frameworks
    Réponses: 8
    Dernier message: 28/10/2005, 20h32
  5. [FPDF] générer des pages PHP en PDF
    Par saint-pere dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 27/09/2005, 18h13

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