Php et pdf

cs_tapi Messages postés 15 Date d'inscription mercredi 1 octobre 2003 Statut Membre Dernière intervention 11 avril 2013 - 17 août 2010 à 15:24
roymatthieu Messages postés 112 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 3 février 2011 - 3 févr. 2011 à 18:42
Bonjour,
J'ai suivi quelques messages du forum à propos de sortir du pdf à partir de PHP et de MYSQL, et tout ce que j'arrive à sortir c'est ce qui l'y a en dessous :

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x?3Rðâ2Ð35W(çr QÐw3T04Ñ30PISp  é(?[?ê?+?€(høæç)dåçd*€e&gdŠ)žži*?dA5?Í0@1CßÍShTÕšªá¥ÊXÁ5ë??é?+?êY??sN@bzª?¡Ÿ!,·ãÔÀ? endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 2 0 obj << /ProcSet /Text /ImageB /ImageC /ImageI /Font << /F1 5 0 R /F2 6 0 R /F3 7 0 R >> /XObject << >> >> endobj 8 0 obj << /Producer (FPDF 1.6) /Title (Mon joli fichier) /Subject (Un exemple de création de fichier PDF) /Author (Un grand écrivain) /Creator (fpdf_cybermonde_org) /CreationDate (D:20100817151939) >> endobj 9 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 10 0000000000 65535 f 0000000287 00000 n 0000000675 00000 n 0000000009 00000 n 0000000087 00000 n 0000000374 00000 n 0000000475 00000 n 0000000571 00000 n 0000000799 00000 n 0000001008 00000 n trailer << /Size 10 /Root 9 0 R /Info 8 0 R >> startxref 1111 %%EOF

Auriez-vous une idée sur ce qu'il manque ?
Merci

7 réponses

inwebo Messages postés 380 Date d'inscription lundi 12 novembre 2007 Statut Membre Dernière intervention 23 octobre 2014
17 août 2010 à 15:31
Un header ?

header('Content-type: application/pdf');



________________________________________
( $toBe || !$toBe ) = $this->Question();
0
cs_tapi Messages postés 15 Date d'inscription mercredi 1 octobre 2003 Statut Membre Dernière intervention 11 avril 2013
17 août 2010 à 15:43
Voilà le tout début du fichier :
<?php
 session_start(); 
 require('fpdf.php');
 // classe étendue pour créer en-tête et pied de page
class PDF extends FPDF
{
// en-tête
function Header()
{
    //Police Arial gras 15
    $this->SetFont('Arial','B',14);
    //Décalage à droite
    $this->Cell(80);
    //Titre
    $this->Cell(30,10,'Mon joli fichier PDF',0,0,'C');
    //Saut de ligne
    $this->Ln(20);
}

// pied de page
function Footer()
{
    //Positionnement à 1,5 cm du bas
    $this->SetY(-15);
    //Police Arial italique 8
    $this->SetFont('Arial','I',8);
    //Numéro de page
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// création du pdf
$pdf=new PDF();
$pdf->SetAuthor('Un grand écrivain');
$pdf->SetTitle('Mon joli fichier');
$pdf->SetSubject('Un exemple de création de fichier PDF');
$pdf->SetCreator('fpdf_cybermonde_org');
$pdf->AliasNBPages();
$pdf->AddPage();


Après j'enchaine la suite
0
syndrael Messages postés 2378 Date d'inscription lundi 4 février 2002 Statut Membre Dernière intervention 29 décembre 2012 20
17 août 2010 à 22:06
Et après ton ?> en fin de fichier il y a peut etre un retour chariot planqué.. ??
S.
0
cs_tapi Messages postés 15 Date d'inscription mercredi 1 octobre 2003 Statut Membre Dernière intervention 11 avril 2013
19 août 2010 à 09:40
Merci pour la réponse,
En fin de compte ce code ne me va pas. Je recherche "simplement" à afficher les données issues de ma base sous une forme de fichier PDF.
Si vous aviez un exemple de code ...
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_tapi Messages postés 15 Date d'inscription mercredi 1 octobre 2003 Statut Membre Dernière intervention 11 avril 2013
20 août 2010 à 11:41
Bonjour,
J'avance dans mon projet à petits pas, mais j'avance.
Je bute malgré tout pour récupérer une variable créée dans une page précédente et l'utiliser dans le script de création du pdf.
Je pensais rajouter session_start(); sur la première ligne du script, mais cela empêche la création du pdf.
Auriez-vous une idée ?
Merci
0
annyphp Messages postés 4 Date d'inscription vendredi 7 janvier 2011 Statut Membre Dernière intervention 15 février 2011
22 janv. 2011 à 11:10


<?php
002	//this class is not part of Resize and upload image class.
003	//this class is property of some one else.
004	//I get this from phpclasses.org but forget the name of author.
005	//sorry for that.
006	 
007	class Image {
008	        var $FileName;
009	        var $FileSize;
010	        var $FileType;
011	        var $AllowedExtentions =  array ("image/png", "image/gif", "image/jpeg", "image/pjpeg", "image/jpg");
012	        var $newWidth = 100; // new width
013	        var $newHeight = 100; //new height
014	        var $TmpName;
015	        var $PicDir;  //store uploaded images
016	        var $MaxFileSize = 2000000;  //kbytes  
017	        var $ImageQuality = 100;  // image compression (max value 100)
018	 
019	        function Image($FileName) {
020	            $this->FileName=$FileName;
021	        }
022	         
023	        function GetInfo() {
024	            $out='  

Upload success!

025	                        Name: '.$this->FileName.'

026	                    file size: '.$this->FileSize.' byte

027	                    file type: '.$this->FileType.'

028	                    PicDir .  $this->FileName . '>

';
029	                     
030	            return $out;       
031	        }
032	         
033	          
034	         function GetFileExtention ($FileName) {
035	            if (in_array ($this->FileType, $this -> AllowedExtentions)) {
036	                return true;       
037	            }   else {
038	               return false;           
039	            }          
040	          
041	         }         
042	          
043	         function ExistFile () {
044	            $fileexist = $_SERVER['DOCUMENT_ROOT']  .
045	                          dirname($_SERVER['PHP_SELF']) .
046	                          '/' . $this->PicDir . 
047	                                $this->FileName;
048	                if (file_exists($fileexist)) { return true; }
049	            }
050	          
051	        function GetError ($error) {
052	             
053	            switch ($error) {          
054	                case 0 :
055	                    return "Error: Invalid file type  $this->FileType ! Allow type: .jpg, .jpeg, .gif, .png  $this->FileName
";
056	                break;
057	                 
058	                case 1 :
059	                    return "Error: File $this->FileSize is too large! You must upload 1000 MB file
";
060	                break;             
061	                 
062	                case 2 :
063	                    return "Error: Please, select a file for uploading!
";
064	                break;
065	                                     
066	                case 3 :
067	                    return "Error: File $this->FileName already exist!
";
068	                break;             
069	            }
070	             
071	        }
072	 
073	         
074	         function Resize () {
075	        // header('Content-Type: image/gif');
076	            if (empty  ($this->TmpName))                                         {return $this -> GetError (2);}
077	                else if ($this->FileSize > $this->MaxFileSize)                 {return $this -> GetError (1);}                     
078	                else if ($this -> GetFileExtention ($this->FileName)  == false)    {return $this -> GetError (0);}
079	                else if ($this -> ExistFile())                                   {return $this -> GetError (3);}
080	                     
081	                    else {
082	                 
083	            $ext = explode(".",$this->FileName);
084	            $ext = end($ext);
085	            $ext = strtolower($ext);
086	             
087	            // Get new sizes
088	            list($width_orig, $height_orig) = getimagesize($this->TmpName);
089	 
090	            $ratio_orig = $width_orig/$height_orig;
091	 
092	                if ($this->newWidth/$this->newHeight > $ratio_orig) {
093	            $this->newWidth = $this->newHeight*$ratio_orig;
094	                } else {
095	            $this->newHeight = $this->newWidth/$ratio_orig;
096	                }
097	 
098	            $normal  = imagecreatetruecolor($this->newWidth, $this->newHeight);
099	 
100	            if          ($ext "jpg") { $source imagecreatefromjpeg($this->TmpName);  }
101	            else if     ($ext "gif") { $source imagecreatefromgif ($this->TmpName);  }
102	            else if     ($ext == "png")
103	            {
104	                $this->ImageQuality = 9;
105	                $source = imagecreatefrompng ($this->TmpName); 
106	            }
107	 
108	            imagecopyresampled($normal, $source,    0, 0, 0, 0, $this->newWidth, $this->newHeight, $width_orig, $height_orig);
109	 
110	 
111	            if          ($ext == "jpg") {
112	                                //ob_start();
113	                                imagejpeg($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality");
114	                                //$binaryThumbnail = ob_get_contents();
115	                                //ob_end_clean();
116	                                }
117	            else if     ($ext == "gif") { imagegif ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality");  }
118	            else if     ($ext == "png") { imagepng ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality");  }
119	 
120	            imagedestroy($source);
121	             
122	            //echo $this -> GetInfo();
123	                         
124	        }  
125	     
126	    }              
127	                            
128	        function Save() {      
129	                if (empty  ($this->TmpName))                                     {return $this -> GetError (2);}
130	                else if ($this->FileSize > $this->MaxFileSize)                 {return $this -> GetError (1);}                     
131	                else if ($this -> GetFileExtention ($this->FileName) == false)    {return $this -> GetError (0);}
132	                else if ($this -> ExistFile ())                              {return $this -> GetError (3);}        
133	                     
134	                    else {
135	             
136	                copy($this->TmpName,$this->PicDir.$this->FileName);
137	             
138	                //echo $this -> GetInfo();
139	                     
140	             }
141	         }
142	     }
143	 
144	?>[code=php]
/code
PHP PDF script
0
roymatthieu Messages postés 112 Date d'inscription jeudi 31 août 2006 Statut Membre Dernière intervention 3 février 2011 1
3 févr. 2011 à 18:42
Ccou,

Et du coté de la fonction Output() (ou un truc comme ça) de la classe FPDF...

Tu devrais trouver les infos dans la manuel de la classe (sur leur site web)...

+++
0
Rejoignez-nous