ILIAS  release_8 Revision v8.24
class.ilTCPDFRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected ilLanguage $lng;
27
28 public function __construct()
29 {
30 global $DIC;
31 $this->lng = $DIC->language();
32 }
33
34 public function addConfigElementsToForm(ilPropertyFormGUI $form, string $service, string $purpose): void
35 {
36 $margin_left = new ilTextInputGUI($this->lng->txt('margin_left'), 'margin_left');
37 $form->addItem($margin_left);
38
39 $margin_top = new ilTextInputGUI($this->lng->txt('margin_top'), 'margin_top');
40 $form->addItem($margin_top);
41
42 $margin_right = new ilTextInputGUI($this->lng->txt('margin_right'), 'margin_right');
43 $form->addItem($margin_right);
44
45 $margin_bottom = new ilTextInputGUI($this->lng->txt('margin_bottom'), 'margin_bottom');
46 $form->addItem($margin_bottom);
47
48 $image_scale = new ilTextInputGUI($this->lng->txt('image_scale'), 'image_scale');
49 $form->addItem($image_scale);
50 }
51
52 public function populateConfigElementsInForm(ilPropertyFormGUI $form, string $service, string $purpose, array $config): void
53 {
54 $form->getItemByPostVar('margin_left')->setValue($config['margin_left']);
55 $form->getItemByPostVar('margin_right')->setValue($config['margin_right']);
56 $form->getItemByPostVar('margin_top')->setValue($config['margin_top']);
57 $form->getItemByPostVar('margin_bottom')->setValue($config['margin_bottom']);
58 $form->getItemByPostVar('image_scale')->setValue($config['image_scale']);
59 }
60
61 public function validateConfigInForm(ilPropertyFormGUI $form, string $service, string $purpose): bool
62 {
63 return true;
64 }
65
66 public function getConfigFromForm(ilPropertyFormGUI $form, string $service, string $purpose): array
67 {
68 $retval = [
69 'margin_left' => $form->getItemByPostVar('margin_left')->getValue(),
70 'margin_right' => $form->getItemByPostVar('margin_right')->getValue(),
71 'margin_top' => $form->getItemByPostVar('margin_top')->getValue(),
72 'margin_bottom' => $form->getItemByPostVar('margin_bottom')->getValue(),
73 'image_scale' => $form->getItemByPostVar('image_scale')->getValue(),
74 ];
75
76 return $retval;
77 }
78
79 public function getDefaultConfig(string $service, string $purpose): array
80 {
81 $retval = [
82 'margin_left' => '10',
83 'margin_top' => '10',
84 'margin_right' => '10',
85 'margin_bottom' => '10',
86 'image_scale' => '1',
87 ];
88
89 return $retval;
90 }
91
92 public function prepareGenerationRequest(string $service, string $purpose): void
93 {
97 ->setDpi(600)
98 ->setZoomFactor(0.17);
99 }
100
101 public function generatePDF(string $service, string $purpose, array $config, ilPDFGenerationJob $job): void
102 {
103 // create new PDF document
104 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
105
106 $pdf->SetMargins($config['margin_left'], $config['margin_top'], $config['margin_right']);
107 $pdf->SetAutoPageBreak('auto', $config['margin_bottom']);
108 $pdf->setImageScale($config['image_scale']);
109
110 $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
111 $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
112 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
113 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
114 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
115 $pdf->SetFont('dejavusans', '', 10);
116 $pdf->setSpacesRE('/[^\S\xa0]/'); // Fixing unicode/PCRE-mess #17547
117
118 foreach ($job->getPages() as $page) {
119 $page = ' ' . $page;
120 $pdf->AddPage();
121 $pdf->writeHTML($page, true, false, true, false, '');
122 }
123 $result = $pdf->Output($job->getFilename(), $job->getOutputMode()); // (I - Inline, D - Download, F - File)
124
125 if (in_array($job->getOutputMode(), ['I', 'D'])) {
126 exit();
127 }
128 }
129}
language handling
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
const PURPOSE_PDF
const RENDER_PNG_AS_IMG_EMBED
This class represents a property form user interface.
getItemByPostVar(string $a_post_var)
getDefaultConfig(string $service, string $purpose)
prepareGenerationRequest(string $service, string $purpose)
Prepare the content processing at the beginning of a PDF generation request Should be used to initial...
populateConfigElementsInForm(ilPropertyFormGUI $form, string $service, string $purpose, array $config)
validateConfigInForm(ilPropertyFormGUI $form, string $service, string $purpose)
generatePDF(string $service, string $purpose, array $config, ilPDFGenerationJob $job)
getConfigFromForm(ilPropertyFormGUI $form, string $service, string $purpose)
addConfigElementsToForm(ilPropertyFormGUI $form, string $service, string $purpose)
This class represents a text property in a property form.
global $DIC
Definition: feed.php:28
exit
Definition: login.php:28
$service
Definition: ltiservices.php:43
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85