Bonjour,

Je voudrais pouvoir imprimer une table dans un PDF, j'ai donc fait une recherche sur google qui ma renvoyé sur http://www.fpdf.org/.

Après avoir lu j'ai fait un premier test:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
<?php
require('fpdf.php');
 
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World !');
$pdf->Output();
?>
ça ma bien afficher un Hello World en PDF.

Ensuite j'ai essayé avec Mysql imprimer une table en me basant sur un exemple du site fpdf :

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
 
<?php
//PDF USING MULTIPLE PAGES
//CREATED BY: Carlos Vasquez S.
//E-MAIL: cvasquez@cvs.cl
//CVS TECNOLOGIA E INNOVACION
//SANTIAGO, CHILE
 
require('fpdf.php');
 
//Connect to your database
include("conectmysql.php");
 
//Create new pdf file
$pdf=new FPDF();
 
//Disable automatic page break
$pdf->SetAutoPageBreak(false);
 
//Add first page
$pdf->AddPage();
 
//set initial y axis position per page
$y_axis_initial = 25;
 
//print column titles
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(30,6,'ID_CANDIDAT',1,0,'L',1);
$pdf->Cell(100,6,'NOM',1,0,'L',1);
$pdf->Cell(30,6,'PRENOM',1,0,'R',1);
 
$y_axis = $y_axis + $row_height;
 
//Select the Products you want to show in your PDF file
$result=mysql_query('select ID_CANDIDAT,NOM,PRENOM from tbl_candidats ORDER BY ID_CANDIDAT',$link);
 
//initialize counter
$i = 0;
 
//Set maximum rows per page
$max = 25;
 
//Set Row Height
$row_height = 6;
 
while($row = mysql_fetch_array($result))
{
    //If the current row is the last one, create new page and print column title
    if ($i == $max)
    {
        $pdf->AddPage();
 
        //print column titles for the current page
        $pdf->SetY($y_axis_initial);
        $pdf->SetX(25);
        $pdf->Cell(30,6,'ID_CANDIDAT',1,0,'L',1);
        $pdf->Cell(100,6,'NOM',1,0,'L',1);
        $pdf->Cell(30,6,'PRENOM',1,0,'R',1);
 
        //Go to next row
        $y_axis = $y_axis + $row_height;
 
        //Set $i variable to 0 (first row)
        $i = 0;
    }
 
    $id = $row['ID_CANDIDAT'];
    $nom = $row['NOM'];
    $prenom = $row['PRENOM'];
 
    $pdf->SetY($y_axis);
    $pdf->SetX(25);
    $pdf->Cell(30,6,$id,1,0,'L',1);
    $pdf->Cell(100,6,$nom,1,0,'L',1);
    $pdf->Cell(30,6,$prenom,1,0,'R',1);
 
    //Go to next row
    $y_axis = $y_axis + $row_height;
    $i = $i + 1;
}
 
mysql_close($link);
 
//Send file
$pdf->Output();
?>
Et la j'ai droit a des erreurs:

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
 
Notice: Undefined variable: row_height in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 34
 
Notice: Undefined variable: y_axis in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 34
 
Notice: Undefined variable: link in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 37
 
Warning: mysql_query() expects parameter 2 to be resource, null given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 37
 
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 48
 
Notice: Undefined variable: link in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 84
 
Warning: mysql_close() expects parameter 1 to be resource, null given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\test.php on line 84
FPDF error: Some data has already been output, can't send PDF file
Pourtant je me suis basé sur l'exemple.

Que faire ??? je sais que Undefined variable: row_height veut dire que ma variable n'est pas définie mais même si je la définie ça ne change rien.

D'avance merci

D'avance merci