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] Création PDF et navigateur


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Débutant  
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Points : 170
    Points
    170
    Par défaut [FPDF] Création PDF et navigateur
    bonjour à tous

    fichier sector.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
     
    <?php
    require('fpdf/fpdf.php');
     
    class PDF_Sector extends FPDF
    {
    	function Sector($xc, $yc, $r, $a, $b, $style='FD', $cw=true, $o=90)
    	{
    		$d0 = $a - $b;
    		if($cw){
    			$d = $b;
    			$b = $o - $a;
    			$a = $o - $d;
    		}else{
    			$b += $o;
    			$a += $o;
    		}
    		while($a<0)
    			$a += 360;
    		while($a>360)
    			$a -= 360;
    		while($b<0)
    			$b += 360;
    		while($b>360)
    			$b -= 360;
    		if ($a > $b)
    			$b += 360;
    		$b = $b/360*2*M_PI;
    		$a = $a/360*2*M_PI;
    		$d = $b - $a;
    		if ($d == 0 && $d0 != 0)
    			$d = 2*M_PI;
    		$k = $this->k;
    		$hp = $this->h;
    		if (sin($d/2))
    			$MyArc = 4/3*(1-cos($d/2))/sin($d/2)*$r;
    		else
    			$MyArc = 0;
    		//first put the center
    		$this->_out(sprintf('%.2F %.2F m',($xc)*$k,($hp-$yc)*$k));
    		//put the first point
    		$this->_out(sprintf('%.2F %.2F l',($xc+$r*cos($a))*$k,(($hp-($yc-$r*sin($a)))*$k)));
    		//draw the arc
    		if ($d < M_PI/2){
    			$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
    						$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
    						$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
    						$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
    						$xc+$r*cos($b),
    						$yc-$r*sin($b)
    						);
    		}else{
    			$b = $a + $d/4;
    			$MyArc = 4/3*(1-cos($d/8))/sin($d/8)*$r;
    			$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
    						$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
    						$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
    						$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
    						$xc+$r*cos($b),
    						$yc-$r*sin($b)
    						);
    			$a = $b;
    			$b = $a + $d/4;
    			$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
    						$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
    						$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
    						$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
    						$xc+$r*cos($b),
    						$yc-$r*sin($b)
    						);
    			$a = $b;
    			$b = $a + $d/4;
    			$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
    						$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
    						$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
    						$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
    						$xc+$r*cos($b),
    						$yc-$r*sin($b)
    						);
    			$a = $b;
    			$b = $a + $d/4;
    			$this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a),
    						$yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a),
    						$xc+$r*cos($b)+$MyArc*cos($b-M_PI/2),
    						$yc-$r*sin($b)-$MyArc*sin($b-M_PI/2),
    						$xc+$r*cos($b),
    						$yc-$r*sin($b)
    						);
    		}
    		//terminate drawing
    		if($style=='F')
    			$op='f';
    		elseif($style=='FD' || $style=='DF')
    			$op='b';
    		else
    			$op='s';
    		$this->_out($op);
    	}
     
    	function _Arc($x1, $y1, $x2, $y2, $x3, $y3 )
    	{
    		$h = $this->h;
    		$this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c',
    			$x1*$this->k,
    			($h-$y1)*$this->k,
    			$x2*$this->k,
    			($h-$y2)*$this->k,
    			$x3*$this->k,
    			($h-$y3)*$this->k));
    	}
    }
    ?>
    ficher index.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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
     
    <?php
     
    require('sector.php');
     
     
    class PDF_Diag extends PDF_Sector  
    {
    	var $legends;
        var $wLegend;
        var $sum;
        var $NbVal;
     
     
        function ColumnChart($gr1='',$gr2='',$w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
        {
     
            // RGB for color 0
            $colors[0][0] = 1;
            $colors[0][1] = 111;
            $colors[0][2] = 174;
     
            // RGB for color 1
            $colors[1][0] = 0;
            $colors[1][1] = 155;
            $colors[1][2] = 0;
     
            // RGB for color 2
            $colors[2][0] = 75;
            $colors[2][1] = 155;
            $colors[2][2] = 255;
     
            // RGB for color 3
            $colors[3][0] = 75;
            $colors[3][1] = 0;
            $colors[3][2] = 155;
     
            $this->SetFont('times', '', 10);
            $this->SetLegends($data,$format);
     
            // Starting corner (current page position where the chart has been inserted)
            $XPage = $this->GetX();
            $YPage = $this->GetY();
            $margin = 2; 
     
            // Y position of the chart
            $YDiag = $YPage + $margin;
     
            // chart HEIGHT
            $hDiag = floor($h - $margin * 2);
     
            // X position of the chart
            $XDiag = $XPage + $margin;
     
            // chart LENGHT
            $lDiag = floor($w - $margin * 3 - $this->wLegend);
     
            if($color == null)
            $color=array(155,155,155);
            if ($maxVal == 0) 
            {
                foreach($data as $val)
                {
                    if(max($val) > $maxVal)
                    {
                        $maxVal = max($val);
                    }
                }
            }
     
            // define the distance between the visual reference lines (the lines which cross the chart's internal area and serve as visual reference for the column's heights)
            $valIndRepere = ceil($maxVal / $nbDiv);
     
            // adjust the maximum value to be plotted (recalculate through the newly calculated distance between the visual reference lines)
            $maxVal = $valIndRepere * $nbDiv;
     
            // define the distance between the visual reference lines (in milimeters)
            $hRepere = floor($hDiag / $nbDiv);
     
            // adjust the chart HEIGHT
            $hDiag = $hRepere * $nbDiv;
     
            // determine the height unit (milimiters/data unit)
            $unit = $hDiag / $maxVal;
     
            // determine the bar's thickness
            $lBar = floor($lDiag / ($this->NbVal + 1));
            $lDiag = $lBar * ($this->NbVal + 1);
            $eColumn = floor($lBar * 70 / 100);
     
            $this->SetFillColor(1,111,174);
            $this->Rect(100, $YDiag-10, 5, 5, 'DF');
    	$this->SetXY(107, $YDiag-10);
            $this->Cell(0,5,$gr1);
     
            $this->SetFillColor(0,155,0);
            $this->Rect(100, $YDiag, 5, 5, 'DF');
    		$this->SetXY(107, $YDiag);
            $this->Cell(0,5,$gr2);
     
            $YDiag=$YDiag+10;
            // draw the chart border
            $this->SetLineWidth(0.2);
            $this->Rect($XDiag, $YDiag, $lDiag, $hDiag);
            $this->SetFont('times', '', 11);
            $this->SetFillColor($color[0],$color[1],$color[2]);
            $i=0;
            foreach($data as $val) 
            {
                //Column
                $yval = $YDiag + $hDiag;
                $xval = $XDiag + ($i + 1) * $lBar - $eColumn/2;
                $lval = floor($eColumn/(count($val)));
                $j=0;
                foreach($val as $v)
                {
                    $hval = (int)($v * $unit);
                    $this->SetFillColor($colors[$j][0], $colors[$j][1], $colors[$j][2]);
                    $this->Rect($xval+($lval*$j), $yval, $lval, -$hval, 'DF');
                    $j++;
                }
     
                //Legend
                $this->SetXY($xval+5, $yval + $margin+10);
                //$this->Cell($lval, 20, $this->legends[$i],0,0,'C');
                 $this->Cell($lval+10, 30, $this->RotatedText($xval+3,$yval+$margin+1,$this->legends[$i],-45),0,0,'C');
     
                $i++;
            }
     
            //Scales
            for ($i = 0; $i <= $nbDiv; $i++) 
            {
                $ypos = $YDiag + $hRepere * $i;
                $this->Line($XDiag, $ypos, $XDiag + $lDiag, $ypos);
                $val = ($nbDiv - $i) * $valIndRepere;
                $ypos = $YDiag + $hRepere * $i;
                $xpos = $XDiag - $margin - $this->GetStringWidth($val);
                $this->Text($xpos, $ypos, $val);
            }
     
     
        }
     
        function SetLegends($data, $format)
        {
              $this->legends=array();
    		$this->wLegend=0;
    		$this->sum=array_sum($data);
    		$this->NbVal=count($data);
    		foreach($data as $l=>$val)
    		{
    			$legend=$l;
    			$this->legends[]=$legend;
    			$this->wLegend=max($this->GetStringWidth($legend),$this->wLegend);
    		}
        }
     
     
    	var $angle=0;
     
    	function Rotate($angle,$x=-1,$y=-1)
    	{
    		if($x==-1)
    			$x=$this->x;
    		if($y==-1)
    			$y=$this->y;
    		if($this->angle!=0)
    			$this->_out('Q');
    		$this->angle=$angle;
    		if($angle!=0)
    		{
    			$angle*=M_PI/180;
    			$c=cos($angle);
    			$s=sin($angle);
    			$cx=$x*$this->k;
    			$cy=($this->h-$y)*$this->k;
    			$this->_out(sprintf('q %.20F %.20F %.20F %.20F %.20F %.20F cm 1 0 0 1 %.20F %.20F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
    		}
    	}
     
    	function _endpage()
    	{
    		if($this->angle!=0)
    		{
    			$this->angle=0;
    			$this->_out('Q');
    		}
    		parent::_endpage();
    	}
     
     
    	function RotatedText($x,$y,$txt,$angle)
    	{
    		//Text rotated around its origin
    		$this->Rotate($angle,$x,$y);
    		$this->Text($x,$y,$txt);
    		$this->Rotate(0);
    	}
     
       function Footer()
       {
     
           $this->SetY(-15);
           $this->SetFont('Times','I',10);
           //Numéro de page
           $this->Cell(0,5,'Page '.$this->PageNo().'/{nb}',0,0,'C');
       }
    }
     
    $pdf = new PDF_Diag();
    $pdf->AddPage();
     
    $data[0] = array( 10,90);
    $data[1] = array( 30,110);
    $data[2] = array( 100);
     
     
    // Column chart
    $pdf->SetFont('Times', 'BU', 12);
    $pdf->Cell(210, 5, 'sssssssss', 0, 1, 'C');
    $pdf->Ln(8);
    $valX = $pdf->GetX();
    $valY = $pdf->GetY();
    $pdf->ColumnChart('hhh','jj',110, 100, $data, '%l : %v (%p)', array(255,175,100));
    //$pdf->SetXY($valX, $valY);
     
    $pdf->Output();
     
     
    ?>
    le fichier est bien enregistré mais mon soucis est:

    quand j'ouvre le fichier avec le navigateur j'aurai mon graphe avec toutes les légendes mais quand je l'ouvre avec adobe reader le graphe n’apparaît pas
    merci

  2. #2
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Tu l'ouvres dans Adobe en l'ayant enregistré à partir du fichier ouvert dans le navigateur ?
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

Discussions similaires

  1. [FPDF] création d'un pdf au format prédéfini
    Par javaboy dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 15/06/2007, 09h13
  2. [FPDF] Création de fichier pdf avec fdf
    Par tyler22 dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 20/02/2007, 13h50
  3. [FPDF] Création dynamique d'un document PDF
    Par loka dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 21/07/2006, 15h37
  4. [FPDF] Création de PDF
    Par Taz_8626 dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 18/04/2006, 15h48
  5. [FPDF] création d'un interface pour accés à des fichiers PDF
    Par StyleXP dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 19/12/2005, 10h18

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