public function genererPDFAction($annee) { $pdf = new PDF(); $pdf->setSourceFile($this->get('kernel')->getRootDir() . "/../papierBase.pdf"); $tpl = $pdf->importPage(1); $pdf->addPage(); $pdf->useTemplate($tpl, 0, 0, 0, 0, true); $pdf->SetFont('Arial', 'BIU', 18); $pdf->SetTextColor(91, 155, 213); $pdf->SetXY(65, 30); $pdf->Write(0, 'Dates des exercices ' . $annee); $pdf->SetFont('Arial', 'B', 12); $pdf->SetTextColor(0, 0, 0); $pdf->SetY(60); $pdf->SetFillColor(160, 191, 220); $header = array('Exercice', 'Date', 'Horaire', 'Emplacement'); // Largeurs des colonnes $w = array(65, 20, 40, 65); // En-tête for ($i = 0; $i < count($header); $i++) { $pdf->Cell($w[$i], 10, $header[$i], 1, 0, 'C', true); } $pdf->Ln(); // Données $pdf->SetFont('Arial', '', 11); $pdf->SetFillColor(224, 240, 255); $evenements = $this->getDoctrine()->getManager()->getRepository('JspDynamiqueBundle:Evenement')->evenementsAnnuels($annee); $fill = false; foreach ($evenements as $evenement) { $pdf->Cell($w[0], 8, utf8_decode($evenement->getTitre()), 1, 0, '', $fill); $pdf->Cell($w[1], 8, $evenement->getDate()->format('d\\/m'), 1, 0, '', $fill); $pdf->Cell($w[2], 8, $evenement->getDate()->format('H\\hi') . ' -> ' . $evenement->getDateFin()->format('H\\hi'), 1, 0, '', $fill); $pdf->Cell($w[3], 8, utf8_decode($evenement->getDescription()), 1, 1, '', $fill); $fill = !$fill; } // Trait de terminaison $pdf->Cell(array_sum($w), 0, '', 'T'); //La reponse $reponse = new Response(); $reponse->headers->set('Content-Type', 'application/pdf'); $pdf->Output(); return $reponse; }
public function pdfAction($annee, $format) { $this->get('sdis_affichage.comservice')->purger(); $pdf = new PDF(); $pdf->addPage('p', $format); $pdf->SetFont('Arial', 'B', 12); $pdf->SetXY(60, 7); if ($annee != 0) { $pdf->Write(0, 'PLANNING DES TOURNUS DE PIQUETS ' . $annee); } else { $pdf->Write(0, 'PLANNING DES TOURNUS DE PIQUETS ' . date('Y')); } $pdf->Ln(7); if ($format == 'A3') { $largeur = array(12, 15, 15, 8, 8, 8, 8, 50, 50, 50, 50); $deportX = 134; } else { $largeur = array(10, 10, 10, 8, 8, 8, 8, 33, 33, 33, 33); $deportX = 105; } $entetes = array("Date", '', '', 'Serv', 'Renf', 'Serv', 'Renf', 'Chef d\'intervention', 'Chef de groupe', 'Chauffeur', 'Intervenant'); $mois = array('', 'janv', 'févr', 'mars', 'avr', 'mai', 'juin', 'juil', 'août', 'sept', 'oct', 'nov', 'déc'); $jours = array('DI', 'LU', 'MA', 'ME', 'JE', 'VE', 'SA'); //Têtes de colonnes $pdf->SetFillColor(0, 0, 0); $pdf->SetTextColor(255); $pdf->SetDrawColor(0, 0, 0); if ($format == 'A3') { $pdf->SetFont('Arial', '', 10); } else { $pdf->SetFont('Arial', '', 8); } for ($i = 0; $i < count($entetes); $i++) { $pdf->Cell($largeur[$i], 7, $entetes[$i], 1, 0, 'C', true); } $pdf->Ln(); //Récuperer les piquets $piquets = $this->getDoctrine()->getManager()->getRepository('SdisAffichageBundle:Piquets')->findby(array(), array('debut' => 'ASC')); $pdf->SetTextColor(0); $pdf->SetDrawColor(0, 0, 0); if ($format == 'A3') { $pdf->SetFont('Arial', '', 8); } else { $pdf->SetFont('Arial', '', 6); } foreach ($piquets as $piquet) { if ($piquet->getCoachOfficier() != null or $format == 'A3') { $hauteur = 8; } else { $hauteur = 4; } $debut = $piquet->getDebut(); $fin = $piquet->getFin(); $pdf->Cell($largeur[0], $hauteur, utf8_decode($jours[$debut->format('w')]) . '-' . utf8_decode($jours[$fin->format('w')]), 1, 0); $pdf->Cell($largeur[1], $hauteur, $debut->format('d') . ' ' . utf8_decode($mois[$debut->format('n')]), 1, 0); $pdf->Cell($largeur[2], $hauteur, $fin->format('d') . ' ' . utf8_decode($mois[$fin->format('n')]), 1, 0); $rgb = $this->hex2rgb($piquet->getSectionService()->getCouleur()); $pdf->setFillColor($rgb[0], $rgb[1], $rgb[2]); $pdf->Cell($largeur[3], $hauteur, '', 1, 0, '', true); $rgb = $this->hex2rgb($piquet->getSectionRenfort()->getCouleur()); $pdf->setFillColor($rgb[0], $rgb[1], $rgb[2]); $pdf->Cell($largeur[4], $hauteur, '', 1, 0, '', true); $pdf->Cell($largeur[5], $hauteur, $piquet->getSectionService(), 1, 0); $pdf->Cell($largeur[6], $hauteur, $piquet->getSectionRenfort(), 1, 0); if ($piquet->getCoachOfficier() != null) { $pdf->Cell($largeur[7], 4, utf8_decode($piquet->getChefIntervention()), 'LTR', 2); $pdf->Cell($largeur[7], 4, utf8_decode($piquet->getCoachOfficier()), 'LRB', 0); $pdf->SetXY($deportX, $pdf->GetY() - 4); } else { $pdf->Cell($largeur[7], $hauteur, utf8_decode($piquet->getChefIntervention()), 1, 0); } $pdf->Cell($largeur[8], $hauteur, utf8_decode($piquet->getChefGroupe()), 1, 0); $pdf->Cell($largeur[9], $hauteur, utf8_decode($piquet->getChauffeur()), 1, 0); $pdf->Cell($largeur[10], $hauteur, utf8_decode($piquet->getIntervenant()), 1, 0); $pdf->Ln(); } $reponse = new Response(); $reponse->headers->set('Content-Type', 'application/pdf'); $pdf->Output(); return $reponse; }