/** * Fonction d'initialisation * * @param string $class frontend à utiliser * * @throws CMbException * @return void */ static function init($class) { self::$instance = new $class(); // Vérifier l'existance de la sous-classe if (!is_subclass_of(self::$instance, "CHtmlToPDFConverter")) { throw new CMbException("{$class} not a subclass of CHtmlToPDFConverter"); } }
/** * 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; }
/** * Make a PDF document archive of the sejour (based on soins/print_dossier_soins) * * @param string $title File title * @param bool $replace Replace existing file * * @return bool * @throws CMbException */ function makePDFarchive($title = "Dossier complet", $replace = false) { if (!CModule::getActive("soins")) { return false; } $query = array("m" => "soins", "a" => "print_dossier_soins", "sejour_id" => $this->_id, "dialog" => 1, "offline" => 1, "limit" => 10000, "_aio" => 1, "_aio_ignore_scripts" => 1); $base = $_SERVER["SCRIPT_NAME"] . "?" . http_build_query($query, "", "&"); $result = CApp::serverCall("http://127.0.0.1{$base}"); $content = $result["body"]; $file = new CFile(); $file->setObject($this); $file->file_name = "{$title}.pdf"; $file->file_type = "application/pdf"; /*if ($file->loadMatchingObject()) { if ($replace) { $file->delete(); // New file $file = new CFile(); $file->setObject($this); $file->file_name = "$title.pdf"; $file->file_type = "application/pdf"; } }*/ $file->fillFields(); $file->updateFormFields(); $file->forceDir(); $file->author_id = CAppUI::$user->_id; $compte_rendu = new CCompteRendu(); $compte_rendu->_orientation = "portrait"; $format = CCompteRendu::$_page_formats["a4"]; $page_width = round(72 / 2.54 * $format[0], 2); $page_height = round(72 / 2.54 * $format[1], 2); $compte_rendu->_page_format = array(0, 0, $page_width, $page_height); $content = str_replace("<!DOCTYPE html>", "", $content); CHtmlToPDFConverter::init("CWkHtmlToPDFConverter"); //CHtmlToPDFConverter::init("CPrinceXMLConverter"); $pdf = CHtmlToPDFConverter::convert($content, $compte_rendu->_page_format, $compte_rendu->_orientation); $file->putContent($pdf); if ($msg = $file->store()) { throw new CMbException($msg); } return true; }