Error: fallo al cargar el documento PDF (FPDF)
Jeremyb36
-
Jeremyb36 -
Jeremyb36 -
Hola,
Estoy solicitando ayuda para entender el error que me aparece: "Fallo al cargar el documento PDF (FDPF)".
Estoy usando FPDF por primera vez, así que os pido un poco de orientación; llevo 4 días atascado, he buscado en foros y tratado de comprender todo el sistema FPDF, pero no logro entenderlo, estoy perdido.
Para empezar, tengo un archivo de consultas SQL/Zend para recuperar datos en PGadmin.
public function getByDemande($idDemande, $typeTiers) { $select = $this -> newSelect(true); $select -> from(array('d' => 'Demande')); $select -> join(array('s' => 'Suivi'), 'd."idDemande" = s."idDemande"'); $select -> join(array('t' => $typeTiers),'d."idContact" = t."idTiers"'); $select -> joinLeft(array('tet' => 'TelephoneTiers'), 't."idTiers" = tet."idTiers"'); $select -> joinLeft(array('mt' => 'MailTiers'), 't."idTiers" = mt."idTiers"'); $select -> join(array('at' => 'AdresseTiers'), 't."idTiers" = at."idTiers"'); $select -> where('d."idDemande" = s."idDemande"', $idDemande); $select -> where('d."actif"=?', true); $select -> order('s.dateHeure DESC'); return $this->fetchAll($select); }
Ensuite j’ai mon fichier contrôleur (j’utilise l’architecture MVC), où j’ai une fonction principale qui permet l’impression d’un suivi de la demande en PDF, ainsi que deux autres fonctions (où j’utilise le fameux FPDF) afin de récupérer les données et, de faire mon header et mon tableau de suivi.
public function impressionDemandeAction() { if (!$this->_checkDroit(2)) { return ErrorManager::droitErrorNew($this); } $debug = $this->_debug; // On instancie la barre de progression $progress = new Default_Model_Progress(); $this->_progress = $progress; if ($debug) { parent::init(); } else { parent::initNoRender(); $progress->createTmp(); } $data = $this->_getPostData(); $idDemande = $data['idDemande']; $idTypeTiers = $data['idTypeTiers']; $typeTiers = 'idTypeTiers'; switch ($idTypeTiers) { case TypeTiers::BENEFICIAIRE : $typeTiers = "Beneficiaire"; break; case TypeTiers::SALARIE : $typeTiers = "Salarie"; break; case TypeTiers::PROSPECT : $typeTiers = "Prospect"; break; case TypeTiers::CANDIDAT : $typeTiers = "Candidat"; break; case TypeTiers::ENTOURAGE : $typeTiers = "Entourage"; break; case TypeTiers::FINANCEUR : $typeTiers = "Financeur"; break; case TypeTiers::AUTRE : $typeTiers = "StructureExterne"; break; } try { $debug ? null : $progress->updateTmp(0, "Préparation..."); $gtwDemande = new LogisCom_Model_Gateway_Demande(); $resultatDemande = $gtwDemande->getByDemande($idDemande, $typeTiers); $resultatDemande = $resultatDemande->toArray(); // On crée le document $debug ? null : $progress->updateTmp(50, "Finalisation du document..."); $this->_pdf = new Default_Model_FilePdf('L'); $this-> printHeader(); $this-> tableSuivi(); // On sauvegarde le document if ($debug) { $this->view->success = true; $this->view->results = null; } else { $pathname = $this->_pdf->generate('documents', 'demande'); $progress->closeTmp($pathname['complete'], $pathname['name']); } } catch (Exception $e) { // Prévenir le client de l'erreur $debug ? null : $progress->closeTmp($e->getMessage(), $e->getTraceAsString()); } } private function printHeader() { $lineBreak = 5; $data = $this->_getPostData(); $idDemande = $data['idDemande']; $typeTiers = $data['idTypeTiers']; $gtwDemande = new LogisCom_Model_Gateway_Demande(); $resultatDemande = $gtwDemande->getByDemande($idDemande, $typeTiers); $resultatDemande = $resultatDemande->toArray(); $pdf = $this->_pdf; // Titre du pdf $title = $data['idCivilité']. " " .$data['nom']. " ".$data['prenom']. " - " . $data['idTypeTiers']; $pdf->addTitle($title); // Sous-titre $subtitle = "Demande n° ". $data['idDemande']; if ($data['confidentiel'] == TRUE) { $subtitle2 = "Cette demande est indiquée comme confidentielle"; } $pdf->addSubTitle($subtitle); $pdf->addSubTitle($subtitle2); // Hauteur de ligne. $lineSmallHeight = 3; // Cadre du header $pdf->setLineHeight($lineSmallHeight); $pdf->drawFrame(4); foreach ($resultatDemande as $resDemande) { $dateNaissance = $resultat['dateNaissance']; $adresse = $resultat['idAdresse']; $telephone = $resultat['idTelephone']; $adresseMail = $resultat['idMail']; } $contactNaiss = "Date de naissance :"; $dateButoir = $data['dateHeureButoir']; $dateFin = $data['fin']; $nature = $data['idNatureDemande']; $columnsWidth = array(); $columnsWidth[] = 40; $columnsWidth[] = 100; $columnsWidth[] = 40; $columnsWidth[] = 50; $columnsFontStyle = array(); $columnsFontStyle[] = null; $columnsFontStyle[] = 'B'; $columnsFontStyle[] = 'U' ; 'red'; $columnsFontStyle[] = 'B'; $line1 = array(); $line1[] = $contactNaiss; $line1[] = $dateNaissance; $line1[] = 'Caractéristiques :'; $line1[] = null; $line2 = array(); $line2[] = 'Adresse :'; $line2[] = $adresse; $line2[] = 'Date butoir :'; $line2[] = $dateButoir; $line3 = array(); $line3[] = 'Telephone :'; $line3[] = $telephone; $line3[] = 'Nature :'; $line3[] = $nature; $line4 = array(); $line4[] = 'Adresse email :' ; $line4[] = $adresseMail; $line4[] = 'Demande liée :'; $line4[] = $typeTiers. " " .$data['nom']. " " .$data['prenom']; $content = array( $line1, $line2, $line3, $line4 ); $pdf->newLine($lineSmallHeight / 2); $pdf->drawSimpleTable($columnsWidth, $columnsFontStyle, $content); } private function tableSuivi() { $data = $this->_getPostData(); $gtwDemande = new LogisCom_Model_Gateway_Demande(); $resultatDemande = $gtwDemande->getByDemande($idDemande, $typeTiers); $resultatDemande = $resultatDemande->toArray(); $pdf = $this->_pdf; $typeSuivi = $data['idTypeSuivi']; $lineSmallHeight = 3; $pdf->setLineHeight($lineSmallHeight); $pdf->drawFrame(4); $pdf->setDrawColor($typeSuivi); foreach ($resultatDemande as $suivi) { $typeSuivi = $suivi['idTypeSuivi']; $emetteur = $suivi['expediteur']; $date = $suivi['dateEffet']; $commentaires = $suivi['contenu']; } $columnsWidth = array(); $columnsWidth[] = 15; $columnsWidth[] = 25; $columnsWidth[] = 30; $columnsWidth[] = 20; $columnsWidth[] = 100; $columnsFontStyle = array(); $columnsFontStyle[] = null; $columnsFontStyle[] = 'B'; $columnsFontStyle[] = 'B'; $columnsFontStyle[] = null; $columnsFontStyle[] = 'I'; $line1 = array(); $line1[] = 'Type : '; $line1[] = $typeSuivi; $line1[] = $date; $line1[] = 'Commentaires :'; $line1[] = $commentaires; $line2 = array(); $line2[] = 'Emetteur :'; $line2[] = $emetteur; $content = array( $line1, $line2 ); $pdf->newLine($lineSmallHeight / 2); $pdf->drawSimpleTable($columnsWidth, $columnsFontStyle, $content); }
Voilà tout le code relatif à l’impression du PDF. Je voudrais savoir où je me suis trompé.
Merci d’avance pour votre aide.
EDIT : Correction des balises de code => Ajout du langage afin d’avoir la coloration syntaxique et la numérotation des lignes.
Explications disponibles ici : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
1 respuesta
-
Hola
Verifica que tus archivos .php estén codificados en UTF8 sin BOM
ver el capítulo 1 de este enlace : https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8
--
Cordialmente,
Jordane-
Gracias por tu respuesta jordane45, al final fueron mis índices en la variable $title, están indefinidos. Como en la última función tableSuivi, varios índices están indefinidos, voy a solucionarlo y funcionará ;-)
En cuanto a UTF8 sin BOM, estoy en Aptana y los archivos están declarados por defecto [Default (inherited from container: UTF-8), solo que como soy pasante en la empresa, y es para un gran proyecto de desarrollo web, no tengo que modificar nada en los parámetros del IDE. Solo debo hacer que mis códigos no tengan ningún error de PHP, que era el caso.
Gracias de nuevo por tomarte el tiempo de leer mi novela codificada xD y además, voy a cambiar también mis sintaxis, lo hice en 2 etapas (header&body/tableau) mientras que debería haberlo hecho en 3 etapas (header/body/tableauSuivi), será más legible para mis colegas.
-