示例#1
0
 /**
  * Génération d'un pdf à partir d'une source, avec stream au client si demandé
  *
  * @param string        $content      source html
  * @param boolean       $stream       envoi du pdf au navigateur
  * @param CCompteRendu  $compte_rendu compte-rendu ciblé
  * @param CFile         $file         le CFile pour lequel générer le pdf
  *
  * @return string
  */
 function generatePDF($content, $stream, $compte_rendu, $file)
 {
     $this->content = $this->fixBlockElements($content);
     // Remplacement des champs seulement à l'impression
     $this->content = str_replace("[Général - numéro de page]", "<span class='page'></span>", $this->content);
     $date_lock = "";
     $locker = new CMediusers();
     if ($compte_rendu->valide) {
         $locker = $compte_rendu->loadRefLocker();
         $log_lock = $compte_rendu->loadLastLogForField("valide");
         $date_lock = $log_lock->date;
     }
     $this->content = str_replace("[Meta Données - Date de verrouillage - Date]", $compte_rendu->valide ? CMbDT::format($date_lock, "%d/%m/%Y") : "", $this->content);
     $this->content = str_replace("[Meta Données - Date de verrouillage - Heure]", $compte_rendu->valide ? CMbDT::format($date_lock, "%Hh%M") : "", $this->content);
     $this->content = str_replace("[Meta Données - Verrouilleur - Nom]", $locker->_user_last_name, $this->content);
     $this->content = str_replace("[Meta Données - Verrouilleur - Prénom]", $locker->_user_first_name, $this->content);
     $this->content = str_replace("[Meta Données - Verrouilleur - Initiales]", $locker->_shortview, $this->content);
     CHtmlToPDFConverter::$_page_ordonnance = $compte_rendu->_page_ordonnance;
     $pdf_content = CHtmlToPDFConverter::convert($this->content, $compte_rendu->_page_format, $compte_rendu->_orientation);
     if ($file->_file_path) {
         file_put_contents($file->_file_path, $pdf_content);
     }
     $this->nbpages = preg_match_all("/\\/Page\\W/", $pdf_content, $matches);
     if ($stream) {
         header("Pragma: ");
         header("Cache-Control: ");
         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
         header("Cache-Control: no-store, no-cache, must-revalidate");
         //HTTP/1.1
         header("Cache-Control: post-check=0, pre-check=0", false);
         // END extra headers to resolve IE caching bug
         header("MIME-Version: 1.0");
         header("Content-length: " . strlen($pdf_content));
         header('Content-type: application/pdf');
         header("Content-disposition: inline; filename=\"" . $file->file_name . "\"");
         echo $pdf_content;
     }
     return $pdf_content;
 }