Created
March 27, 2013 18:41
-
-
Save larscwallin/5256901 to your computer and use it in GitHub Desktop.
Revisions
-
larscwallin created this gist
Mar 27, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ <?php /* simplx.dompdf */ $filename = isset($filename) ? $filename : false; $outputto = isset($outputto) ? $outputto : 'file'; $directory = isset($directory) ? $directory : $modx->getOption('assets_path'); $html = isset($html) ? $html : false; $papersize = isset($papersize) ? $papersize : 'a4'; $orientation = isset($orientation) ? $orientation : 'portrait';; $success = false; $domPdf; function writePdf($html, $filename, $outputto, $directory) { global $modx, $domPdf; if (!isset($domPdf)) { // Include the class include(($modx->getOption('core_path').'components/simplx/dompdf/dompdf_config.inc.php')); $domPdf = new DOMPDF(); $domPdf->set_paper($papersize, $orientation); if(!$domPdf){ $modx->log(modX::LOG_LEVEL_ERROR, 'Exception in Snippet: simplx.dompdf, Unable to instantiate domPdf Object'); return false; } } $domPdf->load_html($html); $domPdf->render(); switch($outputto) { //case 'header': // $this->domPdf->stream($fileName); // break; case 'file': if(!is_dir($directory)){ // This directory does not exist so we return false. $modx->log(modX::LOG_LEVEL_ERROR, 'Exception in Snippet: simplx.dompdf, Directory "'.$directory.'" does not exist.'); return false; } $output = $domPdf->output(); $success = file_put_contents(($directory.$filename), $output); if($success){ return true; }else{ return false; } break; case 'string': $output = $domPdf->output(); return $output; break; } return true; } if($html && $filename){ $success = writePdf($html,$filename,$outputto,$directory); if($success){ return true; }else{ $modx->log(modX::LOG_LEVEL_ERROR, 'Exception in Snippet: simplx.dompdf, Unable to create file "'.$fileName.'".'); return false; } }else{ $modx->log(modX::LOG_LEVEL_ERROR, 'Exception in Snippet: simplx.dompdf, Parameters "html" or "fileName" are missing or empty.'); return false; }