Error: Failed to load PDF document (FPDF)

Jeremyb36 -  
 Jeremyb36 -
Hello, I’m asking you for help to understand the error message I’m seeing: “PDF document failed to load (FDPF).” I’m using FPDF for the first time, so I’d like you to guide me a bit. I’ve been struggling for 4 days; I’ve searched on forums and tried to understand the FPDF system, but nothing works, I’m lost. To start with, I have an SQL/Zend query file to retrieve data on 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); }
Then I have my controller file (I’m using MVC architecture), where I have a main function that handles printing a request follow-up in PDF, plus two other functions (where I use the famous FPDF) to retrieve the data and to build the header and the follow-up table.
public function impressionDemandeAction() { if (!$this-> _checkDroit(2)) { return ErrorManager::droitErrorNew($this); } $debug = $this->_debug; // Progress bar instantiation $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(); // Create document $debug ? null : $progress->updateTmp(50, "Finalisation du document..."); $this->_pdf = new Default_Model_FilePdf('L'); $this-> printHeader(); $this-> tableSuivi(); // Save the 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) { // Inform client of error $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; // PDF title $title = $data['idCivilité']. " " .$data['nom']. " ".$data['prenom']. " - " . $data['idTypeTiers']; $pdf->addTitle($title); // Subtitle $subtitle = "Demande n° ". $data['idDemande']; if ($data['confidentiel'] == TRUE) { $subtitle2 = "Cette demande est indiquée comme confidentielle"; } $pdf->addSubTitle($subtitle); $pdf->addSubTitle($subtitle2); // Row height. $lineSmallHeight = 3; // Header frame $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 qui compose l’impression PDF. Je veux 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 answer

  1. jordane45 Posted messages 30427 Registration date   Status Moderator Last intervention   4 831
     
    Hello

    Check that your .php files are encoded in UTF-8 without BOM
    see chapter 1 of this link: https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8

    --
    Best regards, 
    Jordane                                                                 
    0
    1. Jeremyb36
       
      Thank you for your reply jordane45. In the end, it was my indices in the $title variable—they are undefined. Like in the last function tableSuivi, several indices are undefined, I’ll just fix that and it’ll work ;-)

      Regarding UTF-8 without BOM, I’m on Aptana and the files are declared by default [Default (inherited from container: UTF-8). Only since I’m an intern in a company, and it’s for a large web development project, there’s no need for me to change anything in the IDE settings. I just need to make sure my code has no PHP errors, which was the case.

      Thanks again for taking the time to read my coded novel xD and moreover, I’m going to change my syntaxes as well; I did it in 2 steps (header&body/table) whereas I should have done it in 3 steps (header/body/tableauSuivi); it will be more readable for my colleagues.
      0