ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilHtmlToPdfTransformerFactory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once __DIR__ . '/../class.ilAbstractHtmlToPdfTransformer.php';
4 require_once './Services/PDFGeneration/classes/class.ilPDFGenerationJob.php';
5 
11 {
12  const PDF_OUTPUT_DOWNLOAD = 'D';
13  const PDF_OUTPUT_INLINE = 'I';
14  const PDF_OUTPUT_FILE = 'F';
15 
16 
20  protected $lng;
21 
26  public function __construct($component = '')
27  {
28  global $lng;
29  $this->lng = $lng;
30  }
31 
36  protected function generateTempPath($output)
37  {
38  $dir = ilUtil::ilTempnam();
39  if (!is_dir($dir)) {
41  }
42 
43  $output = preg_replace('#[\\\\/:*?"<>|]#', '-', $output);
44  $output = $dir . '/' . $output;
45  return $output;
46  }
47 
56  public function deliverPDFFromHTMLString($src, $output, $delivery_type, $service, $purpose)
57  {
58  $map = ilPDFGeneratorUtils::getRendererMapForPurpose($service, $purpose);
59  $renderer = ilPDFGeneratorUtils::getRendererInstance($map['selected']);
60  $config = ilPDFGeneratorUtils::getRendererConfig($service, $purpose, $map['selected']);
61 
62  if (basename($output) == $output) {
64  }
65 
66  $job = new ilPDFGenerationJob();
67  $job->setFilename($output);
68  $job->addPage($src);
69  $job->setOutputMode($delivery_type);
70 
72  $renderer->generatePDF($service, $purpose, $config, $job);
73  return $this->deliverPDF($output, $delivery_type);
74  }
75 
76 
82  protected function deliverPDF($file, $delivery_type)
83  {
84  if (file_exists($file)) {
85  if (strtoupper($delivery_type) === self::PDF_OUTPUT_DOWNLOAD) {
86  ilUtil::deliverFile($file, basename($file), '', false, true);
87  } elseif (strtoupper($delivery_type) === self::PDF_OUTPUT_INLINE) {
88  ilUtil::deliverFile($file, basename($file), '', true, true);
89  } elseif (strtoupper($delivery_type) === self::PDF_OUTPUT_FILE) {
90  return $file;
91  }
92  return $file;
93  }
94  return false;
95  }
100  protected function createOneFileFromArray(array $src)
101  {
102  $tmp_file = dirname(reset($src)) . '/complete_pages_overview.html';
103  $html_content = '';
104  foreach ($src as $filename) {
105  if (file_exists($filename)) {
106  $html_content .= file_get_contents($filename);
107  }
108  }
109  file_put_contents($tmp_file, $html_content);
110  return $tmp_file;
111  }
112 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
__construct($component='')
ilHtmlToPdfTransformerFactory constructor.
$service
Definition: login.php:15
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Class ilHtmlToPdfTransformerFactory.
Create styles array
The data for the language used.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
Class ilPDFGenerationJob.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.