• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/service/pdfService.php

00001 <?php
00025 class pdfService
00026 {
00032     public function __construct()
00033     {
00034     }
00035 
00043     public function renderView($viewName)
00044     {
00045         $viewObj = BizSystem::getObject($viewName);
00046         if($viewObj)
00047         {
00048             $viewObj->setConsoleOutput(false);
00049             $sHTML = $viewObj->render();
00050             //$sHTML = "Test";
00051             //require_once("dompdf/dompdf_config.inc.php");
00052             $domPdf = new DOMPDF();
00053             $domPdf->load_html($sHTML);
00054             //$dompdf->set_paper($_POST["paper"], $_POST["orientation"]);
00055             $domPdf->render();
00056             $this->output($domPdf);
00057             //$dompdf->stream("dompdf_out.pdf");
00058         }
00059     }
00060 
00061 
00067     public function output($domPdf)
00068     {
00069         //$tmpfile = getcwd()."/tmpfiles";
00070         $tmpDir = APP_HOME."/tmpfiles";
00071         //echo $tmpfile;
00072         $this->cleanFiles($tmpDir, 100);
00073         //Determine a temporary file name in the current directory
00074         $tmpFile = tempnam($tmpDir,'tmp');
00075         $fileName = $tmpFile.'.pdf';
00076         $fileName = str_replace("\\","/",$fileName);
00077         unlink($tmpFile);
00078         //Save PDF to file
00079         $pdfText = $domPdf->output();
00080         $fileHandle = fopen($fileName, 'w') or die("can't open pdf file to write");
00081         fwrite($fileHandle, $pdfText) or die("can't write to the pdf file");
00082         fclose($fileHandle);
00083         //JavaScript redirection
00084         $path_parts = pathinfo($fileName);
00085         $file_download = "tmpfiles/".$path_parts['basename'];
00086         echo "<HTML><BODY onload=\"window.location.href='../$file_download';\"</BODY></HTML>";
00087     }
00088 
00095     public function cleanFiles($dir, $seconds)
00096     {
00097         $currentTime = time();
00098         $dirHandle=opendir($dir);
00099         while($file = readdir($dirHandle))
00100         {
00101             if(substr($file,0,3) == 'tmp' && substr($file,-4) == '.pdf')
00102             {
00103                 $path = $dir.'/'.$file;
00104                 if($currentTime - filemtime($path) > $seconds)
00105                     unlink($path);
00106             }
00107         }
00108         closedir($dirHandle);
00109     }
00110 }
00111 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2