ILIAS  release_8 Revision v8.24
class.ilHtmlToPdfTransformerFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private const PDF_OUTPUT_DOWNLOAD = 'D';
27 private const PDF_OUTPUT_INLINE = 'I';
28 private const PDF_OUTPUT_FILE = 'F';
29
30 protected ilLanguage $lng;
31
32 public function __construct(string $component = '')
33 {
34 global $lng;
35 $this->lng = $lng;
36 }
37
38 protected function generateTempPath(string $output): string
39 {
41 if (!is_dir($dir)) {
43 }
44
45 $output = preg_replace('#[\\\\/:*?"<>|]#', '-', $output);
46 $output = $dir . '/' . $output;
47 return $output;
48 }
49
53 public function deliverPDFFromHTMLString(string $src, string $output, string $delivery_type, string $service, string $purpose)
54 {
56 $renderer = ilPDFGeneratorUtils::getRendererInstance($map['selected']);
57 $config = ilPDFGeneratorUtils::getRendererConfig($service, $purpose, $map['selected']);
58
59 if (basename($output) === $output) {
60 $output = $this->generateTempPath($output);
61 }
62
63 $job = new ilPDFGenerationJob();
64 $job->setFilename($output);
65 $job->addPage($src);
66 $job->setOutputMode($delivery_type);
67
68 $renderer->generatePDF($service, $purpose, $config, $job);
69 return $this->deliverPDF($output, $delivery_type);
70 }
71
72 protected function deliverPDF(string $file, string $delivery_type)
73 {
74 if (file_exists($file)) {
75 if (strtoupper($delivery_type) === self::PDF_OUTPUT_DOWNLOAD) {
76 ilFileDelivery::deliverFileLegacy($file, basename($file), '', false, true);
77 } elseif (strtoupper($delivery_type) === self::PDF_OUTPUT_INLINE) {
78 ilFileDelivery::deliverFileLegacy($file, basename($file), '', true, true);
79 } elseif (strtoupper($delivery_type) === self::PDF_OUTPUT_FILE) {
80 return $file;
81 }
82 return $file;
83 }
84
85 return false;
86 }
87
88 protected function createOneFileFromArray(array $src): string
89 {
90 $tmp_file = dirname(reset($src)) . '/complete_pages_overview.html';
91 $html_content = '';
92 foreach ($src as $filename) {
93 if (file_exists($filename)) {
94 $html_content .= file_get_contents($filename);
95 }
96 }
97 file_put_contents($tmp_file, $html_content);
98 return $tmp_file;
99 }
100}
$filename
Definition: buildRTE.php:78
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
deliverPDF(string $file, string $delivery_type)
deliverPDFFromHTMLString(string $src, string $output, string $delivery_type, string $service, string $purpose)
language handling
static getRendererInstance(string $renderer)
static getRendererConfig(string $service, string $purpose, string $renderer)
static getRendererMapForPurpose(string $service, string $purpose)
$service
Definition: ltiservices.php:43
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85