ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTCPDFRenderer.php
Go to the documentation of this file.
1<?php
2
3require_once './Services/PDFGeneration/interfaces/interface.ilRendererConfig.php';
4require_once './Services/PDFGeneration/interfaces/interface.ilPDFRenderer.php';
5
7{
9 protected $lng;
10
16 public function __construct()
17 {
18 global $DIC;
19 $this->lng = $DIC['lng'];
20 }
21
31 public function addConfigElementsToForm(\ilPropertyFormGUI $form, $service, $purpose)
32 {
33 $margin_left = new ilTextInputGUI($this->lng->txt('margin_left'), 'margin_left');
34 $form->addItem($margin_left);
35
36 $margin_top = new ilTextInputGUI($this->lng->txt('margin_top'), 'margin_top');
37 $form->addItem($margin_top);
38
39 $margin_right = new ilTextInputGUI($this->lng->txt('margin_right'), 'margin_right');
40 $form->addItem($margin_right);
41
42 $margin_bottom = new ilTextInputGUI($this->lng->txt('margin_bottom'), 'margin_bottom');
43 $form->addItem($margin_bottom);
44
45 $image_scale = new ilTextInputGUI($this->lng->txt('image_scale'), 'image_scale');
46 $form->addItem($image_scale);
47 }
48
60 {
61 $form->getItemByPostVar('margin_left')->setValue($config['margin_left']);
62 $form->getItemByPostVar('margin_right')->setValue($config['margin_right']);
63 $form->getItemByPostVar('margin_top')->setValue($config['margin_top']);
64 $form->getItemByPostVar('margin_bottom')->setValue($config['margin_bottom']);
65 $form->getItemByPostVar('image_scale')->setValue($config['image_scale']);
66 }
67
77 public function validateConfigInForm(\ilPropertyFormGUI $form, $service, $purpose)
78 {
79 if (true) {
80 return true;
81 }
82 }
83
93 public function getConfigFromForm(\ilPropertyFormGUI $form, $service, $purpose)
94 {
95 $retval = array(
96 'margin_left' => $form->getItemByPostVar('margin_left')->getValue(),
97 'margin_right' => $form->getItemByPostVar('margin_right')->getValue(),
98 'margin_top' => $form->getItemByPostVar('margin_top')->getValue(),
99 'margin_bottom' => $form->getItemByPostVar('margin_bottom')->getValue(),
100 'image_scale' => $form->getItemByPostVar('image_scale')->getValue(),
101 );
102
103 return $retval;
104 }
105
106
115 public function getDefaultConfig($service, $purpose)
116 {
117 $retval = array(
118 'margin_left' => '10',
119 'margin_top' => '10',
120 'margin_right' => '10',
121 'margin_bottom' => '10',
122 'image_scale' => '1',
123 );
124
125 return $retval;
126 }
127
137 public function prepareGenerationRequest($service, $purpose)
138 {
142 ->setDpi(600)
143 ->setZoomFactor(0.17);
144 }
145
154 public function generatePDF($service, $purpose, $config, $job)
155 {
156 require_once 'libs/composer/vendor/autoload.php';
157
158 // create new PDF document
159 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
160
161 $pdf->SetMargins($config['margin_left'], $config['margin_top'], $config['margin_right']);
162 $pdf->SetAutoPageBreak('auto', $config['margin_buttom']);
163 $pdf->setImageScale($config['image_scale']);
164
165 $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
166 $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
167 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
168 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
169 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
170 $pdf->SetFont('dejavusans', '', 10);
171 $pdf->setSpacesRE('/[^\S\xa0]/'); // Fixing unicode/PCRE-mess #17547
172
173 foreach ($job->getPages() as $page) {
174 $page = ' ' . $page;
175 $pdf->AddPage();
176 $pdf->writeHTML($page, true, false, true, false, '');
177 }
178 $result = $pdf->Output(basename($job->getFilename()), $job->getOutputMode()); // (I - Inline, D - Download, F - File)
179
180 if (in_array($job->getOutputMode(), array('I', 'D'))) {
181 exit();
182 }
183 }
184}
$result
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Singleton: get instance.
const PURPOSE_PDF
const RENDER_PNG_AS_IMG_EMBED
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getItemByPostVar($a_post_var)
Get Item by POST variable.
addConfigElementsToForm(\ilPropertyFormGUI $form, $service, $purpose)
from ilRendererConfig
populateConfigElementsInForm(\ilPropertyFormGUI $form, $service, $purpose, $config)
from ilRendererConfig
validateConfigInForm(\ilPropertyFormGUI $form, $service, $purpose)
from ilRendererConfig
prepareGenerationRequest($service, $purpose)
Prepare the content processing at the beginning of a PDF generation request Should be used to initial...
generatePDF($service, $purpose, $config, $job)
from ilPDFRenderer
getDefaultConfig($service, $purpose)
from ilRendererConfig
getConfigFromForm(\ilPropertyFormGUI $form, $service, $purpose)
from ilRendererConfig
__construct()
from ilPlugin
This class represents a text property in a property form.
exit
Definition: login.php:29
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
$service
Definition: result.php:17
$DIC
Definition: xapitoken.php:46