PdfExport.class.php 1013 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require_once(__DIR__.SLASH.'HtmlExport.class.php');
  3. class PdfExport extends HtmlExport{
  4. public static $mime = 'application/pdf';
  5. public static $extension = 'pdf';
  6. public static $description = 'Fichier informations PDF';
  7. public static function sample($dataset){
  8. $stream = parent::sample($dataset);
  9. $pdf = new Pdf($stream);
  10. $stream = $pdf->generate();
  11. return $stream;
  12. }
  13. public static function from_template($source, $data, $return, $isHtml=true){
  14. $htmlRaw = HtmlExport::from_template($source, $data, $return, $isHtml);
  15. $stream = $return=='stream' ? $htmlRaw : file_get_contents($htmlRaw);
  16. $pdf = new Pdf($stream);
  17. $pdfStream = $pdf->generate();
  18. $destination = File::dir().'tmp'.SLASH.'template.'.time().'-'.rand(0,100).'.pdf';
  19. file_put_contents($destination, $pdfStream);
  20. if($return!='stream') {
  21. unlink($htmlRaw);
  22. return $destination;
  23. }
  24. $stream = file_get_contents($destination);
  25. unlink($destination);
  26. return $stream;
  27. }
  28. }
  29. ?>