ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWkhtmlToPdfConfig.php
Go to the documentation of this file.
1 <?php
2 
4 {
5  const ENABLE_QUIET = true;
9  protected $phpunit = false;
13  protected $config = array();
17  protected $zoom;
21  protected $external_links;
25  protected $enabled_forms;
29  protected $user_stylesheet;
33  protected $greyscale;
37  protected $low_quality;
41  protected $orientation;
45  protected $print_media_type;
49  protected $page_size;
53  protected $javascript_delay;
57  protected $margin_left;
61  protected $margin_right;
65  protected $margin_top;
69  protected $margin_bottom;
73  protected $header_type;
77  protected $header_text_left;
85  protected $header_text_right;
93  protected $header_text_line;
97  protected $header_html;
105  protected $header_html_line;
109  protected $footer_type;
113  protected $footer_text_left;
129  protected $footer_text_line;
133  protected $footer_html;
141  protected $footer_html_line;
145  protected $checkbox_svg;
153  protected $radio_button_svg;
161  protected $path;
165  protected $overwrite_default_font = '';
166 
171  public function __construct($config = null)
172  {
173  if ($config != null && !$config instanceof ilWkhtmlToPdfConfig) {
175  } else {
176  if ($config instanceof ilWkhtmlToPdfConfig) {
178  } else {
179  $this->useDefaultConfig();
180  }
181  }
182  }
183 
187  protected function readConfigFromArray($config)
188  {
189  $this->setKeyIfExists('setZoom', 'zoom', $config);
190  $this->setKeyIfExists('setEnabledForms', 'enable_forms', $config);
191  $this->setKeyIfExists('setExternalLinks', 'external_links', $config);
192  $this->setKeyIfExists('setUserStylesheet', 'user_stylesheet', $config);
193  $this->setKeyIfExists('setLowQuality', 'low_quality', $config);
194  $this->setKeyIfExists('setGreyscale', 'greyscale', $config);
195  $this->setKeyIfExists('setOrientation', 'orientation', $config);
196  $this->setKeyIfExists('setPageSize', 'page_size', $config);
197  $this->setKeyIfExists('setMarginLeft', 'margin_left', $config);
198  $this->setKeyIfExists('setMarginRight', 'margin_right', $config);
199  $this->setKeyIfExists('setFooterHtmlSpacing', 'footer_html_spacing', $config);
200  $this->setKeyIfExists('setFooterHtml', 'footer_html', $config);
201  $this->setKeyIfExists('setFooterTextLine', 'footer_text_line', $config);
202  $this->setKeyIfExists('setFooterTextCenter', 'footer_text_center', $config);
203  $this->setKeyIfExists('setFooterTextCenter', 'footer_text_center', $config);
204  $this->setKeyIfExists('setFooterTextSpacing', 'footer_text_spacing', $config);
205  $this->setKeyIfExists('setFooterTextRight', 'footer_text_right', $config);
206  $this->setKeyIfExists('setFooterTextLeft', 'footer_text_left', $config);
207  $this->setKeyIfExists('setFooterType', 'footer_select', $config);
208  $this->setKeyIfExists('setHeaderHtmlSpacing', 'head_html_spacing', $config);
209  $this->setKeyIfExists('setHeaderHtmlLine', 'head_html_line', $config);
210  $this->setKeyIfExists('setHeaderHtml', 'head_html', $config);
211  $this->setKeyIfExists('setHeaderTextLine', 'head_text_line', $config);
212  $this->setKeyIfExists('setHeaderTextSpacing', 'head_text_spacing', $config);
213  $this->setKeyIfExists('setHeaderTextRight', 'head_text_right', $config);
214  $this->setKeyIfExists('setHeaderTextCenter', 'head_text_center', $config);
215  $this->setKeyIfExists('setHeaderTextLeft', 'head_text_left', $config);
216  $this->setKeyIfExists('setHeaderType', 'header_select', $config);
217  $this->setKeyIfExists('setRadioButtonCheckedSvg', 'radio_button_checked_svg', $config);
218  $this->setKeyIfExists('setRadioButtonSvg', 'radio_button_svg', $config);
219  $this->setKeyIfExists('setCheckboxCheckedSvg', 'checkbox_checked_svg', $config);
220  $this->setKeyIfExists('setCheckboxSvg', 'checkbox_svg', $config);
221  $this->setKeyIfExists('setJavascriptDelay', 'javascript_delay', $config);
222  $this->setKeyIfExists('setPrintMediaType', 'print_media_type', $config);
223  $this->setKeyIfExists('setMarginTop', 'margin_top', $config);
224  $this->setKeyIfExists('setMarginBottom', 'margin_bottom', $config);
225  $this->setKeyIfExists('setOverwriteDefaultFont', 'overwrite_font', $config);
226  }
227 
233  protected function setKeyIfExists($function, $key, $config)
234  {
235  if (array_key_exists($key, $config)) {
236  $this->{$function}($config[$key]);
237  }
238  }
239 
243  protected function readConfigFromObject($config)
244  {
245  $this->setZoom($config->getZoom());
246  $this->setEnabledForms($config->getEnabledForms());
247  $this->setExternalLinks($config->getExternalLinks());
248  $this->setUserStylesheet($config->getUserStylesheet());
249  $this->setLowQuality($config->getLowQuality());
250  $this->setGreyscale($config->getGreyscale());
251  $this->setOrientation($config->getOrientation());
252  $this->setPageSize($config->getPageSize());
253  $this->setMarginLeft($config->getMarginLeft());
254  $this->setMarginRight($config->getMarginRight());
255  $this->setFooterTextLine($config->isFooterTextLine());
256  $this->setFooterTextCenter($config->getFooterTextCenter());
257  $this->setFooterTextSpacing($config->getFooterTextSpacing());
258  $this->setFooterTextRight($config->getFooterTextRight());
259  $this->setFooterTextLeft($config->getFooterTextLeft());
260  $this->setFooterType($config->getFooterType());
261 
262  $this->setFooterHtmlSpacing($config->getFooterHtmlSpacing());
263  $this->setFooterHtml($config->getFooterHtml());
264  $this->setFooterHtmlLine($config->isFooterHtmlLine());
265  $this->setHeaderHtmlSpacing($config->getHeaderHtmlSpacing());
266  $this->setHeaderHtml($config->getHeaderHtml());
267  $this->setHeaderHtmlLine($config->isHeaderHtmlLine());
268  $this->setHeaderTextLine($config->isHeaderTextLine());
269  $this->setHeaderTextSpacing($config->getHeaderTextSpacing());
270  $this->setHeaderTextRight($config->getHeaderTextRight());
271  $this->setHeaderTextCenter($config->getHeaderTextCenter());
272  $this->setHeaderTextLeft($config->getHeaderTextLeft());
273  $this->setHeaderType($config->getHeaderType());
274  $this->setRadioButtonCheckedSvg($config->getRadioButtonCheckedSvg());
275  $this->setRadioButtonSvg($config->getRadioButtonSvg());
276  $this->setCheckboxCheckedSvg($config->getCheckboxCheckedSvg());
277  $this->setCheckboxSvg($config->getCheckboxSvg());
278  $this->setJavascriptDelay($config->getJavascriptDelay());
279  $this->setPrintMediaType($config->getPrintMediaType());
280  $this->setMarginTop($config->getMarginTop());
281  $this->setMarginBottom($config->getMarginBottom());
282  $this->setOverwriteDefaultFont($config->getOverwriteDefaultFont());
283  }
284 
288  public function getZoom()
289  {
290  return $this->zoom;
291  }
292 
296  public function setZoom($zoom)
297  {
298  $this->zoom = $zoom;
299  }
300 
304  public function getEnabledForms()
305  {
306  return $this->enabled_forms;
307  }
308 
313  {
314  $this->enabled_forms = $enabled_forms;
315  }
316 
320  public function getExternalLinks()
321  {
322  return $this->external_links;
323  }
324 
329  {
330  $this->external_links = $external_links;
331  }
332 
336  public function getUserStylesheet()
337  {
338  return $this->user_stylesheet;
339  }
340 
345  {
346  $this->user_stylesheet = $user_stylesheet;
347  }
348 
352  public function getLowQuality()
353  {
354  return $this->low_quality;
355  }
356 
360  public function setLowQuality($low_quality)
361  {
362  $this->low_quality = $low_quality;
363  }
364 
368  public function getGreyscale()
369  {
370  return $this->greyscale;
371  }
372 
376  public function setGreyscale($greyscale)
377  {
378  $this->greyscale = $greyscale;
379  }
380 
384  public function getOrientation()
385  {
386  return $this->orientation;
387  }
388 
392  public function setOrientation($orientation)
393  {
394  $this->orientation = $orientation;
395  }
396 
400  public function getPageSize()
401  {
402  return $this->page_size;
403  }
404 
408  public function setPageSize($page_size)
409  {
410  $this->page_size = $page_size;
411  }
412 
416  public function getMarginLeft()
417  {
418  return $this->margin_left;
419  }
420 
424  public function setMarginLeft($margin_left)
425  {
426  $this->margin_left = $margin_left;
427  }
428 
432  public function getMarginRight()
433  {
434  return $this->margin_right;
435  }
436 
440  public function setMarginRight($margin_right)
441  {
442  $this->margin_right = $margin_right;
443  }
444 
448  public function getFooterHtmlSpacing()
449  {
451  }
452 
457  {
458  $this->footer_html_spacing = $footer_html_spacing;
459  }
460 
464  public function getFooterHtml()
465  {
466  return $this->footer_html;
467  }
468 
472  public function setFooterHtml($footer_html)
473  {
474  $this->footer_html = $footer_html;
475  }
476 
480  public function isFooterTextLine()
481  {
483  }
484 
489  {
490  $this->footer_text_line = $footer_text_line;
491  }
492 
496  public function getFooterTextCenter()
497  {
499  }
500 
505  {
506  $this->footer_text_center = $footer_text_center;
507  }
508 
512  public function getFooterTextSpacing()
513  {
515  }
516 
521  {
522  $this->footer_text_spacing = $footer_text_spacing;
523  }
524 
528  public function getFooterTextRight()
529  {
531  }
532 
537  {
538  $this->footer_text_right = $footer_text_right;
539  }
540 
544  public function getFooterTextLeft()
545  {
547  }
548 
553  {
554  $this->footer_text_left = $footer_text_left;
555  }
556 
560  public function getFooterType()
561  {
562  return $this->footer_type;
563  }
564 
568  public function setFooterType($footer_type)
569  {
570  $this->footer_type = $footer_type;
571  }
572 
576  public function isFooterHtmlLine()
577  {
579  }
580 
585  {
586  $this->footer_html_line = $footer_html_line;
587  }
588 
592  public function isHeaderTextLine()
593  {
595  }
596 
601  {
602  $this->header_text_line = $header_text_line;
603  }
604 
608  public function getHeaderTextSpacing()
609  {
611  }
612 
617  {
618  $this->header_text_spacing = $header_text_spacing;
619  }
620 
624  public function getHeaderTextRight()
625  {
627  }
628 
633  {
634  $this->header_text_right = $header_text_right;
635  }
636 
640  public function getHeaderTextCenter()
641  {
643  }
644 
649  {
650  $this->header_text_center = $header_text_center;
651  }
652 
656  public function getHeaderTextLeft()
657  {
659  }
660 
665  {
666  $this->header_text_left = $header_text_left;
667  }
668 
672  public function getHeaderType()
673  {
674  return $this->header_type;
675  }
676 
680  public function setHeaderType($header_type)
681  {
682  $this->header_type = $header_type;
683  }
684 
688  public function getRadioButtonCheckedSvg()
689  {
691  }
692 
697  {
698  $this->radio_button_checked_svg = $radio_button_checked_svg;
699  }
700 
704  public function getRadioButtonSvg()
705  {
707  }
708 
713  {
714  $this->radio_button_svg = $radio_button_svg;
715  }
716 
720  public function getCheckboxCheckedSvg()
721  {
723  }
724 
729  {
730  $this->checkbox_checked_svg = $checkbox_checked_svg;
731  }
732 
736  public function getCheckboxSvg()
737  {
738  return $this->checkbox_svg;
739  }
740 
744  public function setCheckboxSvg($checkbox_svg)
745  {
746  $this->checkbox_svg = $checkbox_svg;
747  }
748 
752  public function getJavascriptDelay()
753  {
755  }
756 
761  {
762  $this->javascript_delay = $javascript_delay;
763  }
764 
768  public function getPrintMediaType()
769  {
771  }
772 
777  {
778  $this->print_media_type = $print_media_type;
779  }
780 
784  public function getMarginTop()
785  {
786  return $this->margin_top;
787  }
788 
792  public function setMarginTop($margin_top)
793  {
794  $this->margin_top = $margin_top;
795  }
796 
800  public function getMarginBottom()
801  {
802  return $this->margin_bottom;
803  }
804 
809  {
810  $this->margin_bottom = $margin_bottom;
811  }
812 
817  public function getOverwriteDefaultFont($renderStyle = false)
818  {
819  if ($renderStyle) {
820  if (strlen($this->overwrite_default_font) > 0) {
821  return '<style>body{font-family: ' . $this->overwrite_default_font . ';}</style>';
822  }
823  } else {
825  }
826 
827  return '';
828  }
829 
834  {
835  $this->overwrite_default_font = $overwrite_default_font;
836  }
837 
838  protected function useDefaultConfig()
839  {
840  $this->setExternalLinks(true);
841  $this->setEnabledForms(false);
842  $this->setJavascriptDelay(500);
843  $this->setZoom(1);
844  $this->setOrientation('Portrait');
845  $this->setPageSize('A4');
846  $this->setMarginLeft('0.5cm');
847  $this->setMarginRight('2cm');
848  $this->setMarginBottom('0.5cm');
849  $this->setMarginTop('2cm');
850  }
851 
855  public static function supportMultiSourcesFiles()
856  {
857  return true;
858  }
859 
863  public function getPath()
864  {
865  return $this->path;
866  }
867 
871  public function setPath($path)
872  {
873  $this->path = $path;
874  }
875 
879  public function getWKHTMLToPdfDefaultPath()
880  {
881  $path = $this->getSavedDefaultBinaryPath();
882  if($path !== ''){
883  return $path;
884  }
885  return '/usr/local/bin/wkhtmltopdf';
886  }
887 
888  public function getConfig()
889  {
890  return $this->config;
891  }
892 
896  public function getCommandLineConfig()
897  {
898  $this->generateCommandLineConfig();
899  $settings = ' ';
900  foreach ($this->config as $value) {
901  $settings .= '--' . $value . ' ';
902  }
903  return $settings;
904  }
905 
906  protected function generateCommandLineConfig()
907  {
908  $this->getZoomArgument();
909  $this->getExternalLinksArgument();
910  $this->getEnabledFormsArgument();
911  $this->getUserStylesheetArgument();
912  $this->getGreyscaleArgument();
913  $this->getLowQualityArgument();
914  $this->getOrientationArgument();
915  $this->getPrintMediaTypeArgument();
916  $this->getPageSizeArgument();
918  $this->getCheckboxSvgArgument();
920  $this->getRadioButtonSvgArgument();
922  $this->getMarginArgument();
923  $this->getHeaderArgument();
924  $this->getFooterArgument();
925  $this->getDebugArgument();
926  $this->getSessionObject();
927  }
928 
929  protected function getZoomArgument()
930  {
931  if ($this->getZoom() != '') {
932  $this->config[] = 'zoom ' . $this->getZoom();
933  }
934  }
935 
936  protected function getExternalLinksArgument()
937  {
938  if ($this->getExternalLinks()) {
939  $this->config[] = 'enable-external-links';
940  } else {
941  $this->config[] = 'disable-external-links';
942  }
943  }
944 
945  protected function getEnabledFormsArgument()
946  {
947  if ($this->getEnabledForms()) {
948  $this->config[] = 'enable-forms';
949  } else {
950  $this->config[] = 'disable-forms';
951  }
952  }
953 
954  protected function getUserStylesheetArgument()
955  {
956  $stylesheet = $this->getUserStylesheet();
957  if ($stylesheet != '') {
958  $this->config[] = 'user-style-sheet "' . $stylesheet . '"';
959  }
960  }
961 
962  protected function getGreyscaleArgument()
963  {
964  if ($this->getGreyscale()) {
965  $this->config[] = 'grayscale';
966  }
967  }
968 
969  protected function getLowQualityArgument()
970  {
971  if ($this->getLowQuality() == 1 || $this->getLowQuality() == true) {
972  $this->config[] = 'lowquality';
973  }
974  }
975 
976  protected function getOrientationArgument()
977  {
978  $orientation = $this->getOrientation();
979  if ($orientation == '' || $orientation == 'Portrait') {
980  $this->config[] = 'orientation Portrait';
981  } else {
982  $this->config[] = 'orientation Landscape';
983  }
984  }
985 
986  protected function getPrintMediaTypeArgument()
987  {
988  if ($this->getPrintMediaType() == 1) {
989  $this->config[] = 'print-media-type';
990  }
991  }
992 
993  protected function getPageSizeArgument()
994  {
995  if ($this->getPageSize() != '') {
996  $this->config[] = 'page-size ' . $this->getPageSize();
997  }
998  }
999 
1000  protected function getJavascriptDelayArgument()
1001  {
1002  if ($this->getJavascriptDelay() != '') {
1003  $this->config[] = 'javascript-delay ' . $this->getJavascriptDelay();
1004  }
1005  }
1006 
1007  protected function getCheckboxSvgArgument()
1008  {
1009  $checkbox_svg = $this->getCheckboxSvg();
1010  if ($checkbox_svg != '') {
1011  $this->config[] = 'checkbox-svg "' . $checkbox_svg . '"';
1012  }
1013  }
1014 
1015  protected function getCheckboxCheckedSvgArgument()
1016  {
1018  if ($checkbox_svg != '') {
1019  $this->config[] = 'checkbox-checked-svg "' . $checkbox_svg . '"';
1020  }
1021  }
1022 
1023  protected function getRadioButtonSvgArgument()
1024  {
1026  if ($radio_button_svg != '') {
1027  $this->config[] = 'radiobutton-svg "' . $radio_button_svg . '"';
1028  }
1029  }
1030 
1032  {
1034  if ($radio_button_svg != '') {
1035  $this->config[] = 'radiobutton-checked-svg "' . $radio_button_svg . '"';
1036  }
1037  }
1038 
1039  protected function getMarginArgument()
1040  {
1041  if ($this->getMarginBottom() != '') {
1042  $this->config[] = 'margin-bottom ' . $this->getMarginBottom();
1043  }
1044  if ($this->getMarginLeft() != '') {
1045  $this->config[] = 'margin-left ' . $this->getMarginLeft();
1046  }
1047  if ($this->getMarginRight() != '') {
1048  $this->config[] = 'margin-right ' . $this->getMarginRight();
1049  }
1050  if ($this->getMarginTop() != '') {
1051  $this->config[] = 'margin-top ' . $this->getMarginTop();
1052  }
1053  }
1054 
1055  protected function getHeaderArgument()
1056  {
1057  $header_value = $this->getHeaderType();
1058  if ($header_value == ilPDFGenerationConstants::HEADER_TEXT) {
1059  $this->config[] = 'header-left "' . $this->getHeaderTextLeft() . '"';
1060  $this->config[] = 'header-center "' . $this->getHeaderTextCenter() . '"';
1061  $this->config[] = 'header-right "' . $this->getHeaderTextRight() . '"';
1062  if ($this->getHeaderTextSpacing() != '') {
1063  $this->config[] = 'header-spacing ' . $this->getHeaderTextSpacing();
1064  }
1065 
1066  if ($this->isHeaderTextLine()) {
1067  $this->config[] = 'header-line';
1068  }
1069  } else {
1070  if ($header_value == ilPDFGenerationConstants::HEADER_HTML) {
1071  $this->config[] = 'header-html "' . $this->getHeaderHtml() . '"';
1072 
1073  if ($this->getHeaderHtmlSpacing() != '') {
1074  $this->config[] = 'header-spacing ' . $this->getHeaderHtmlSpacing();
1075  }
1076  if ($this->isHeaderHtmlLine()) {
1077  $this->config[] = 'header-line';
1078  }
1079  }
1080  }
1081  }
1082 
1086  public function getHeaderHtml()
1087  {
1088  return $this->header_html;
1089  }
1090 
1094  public function setHeaderHtml($header_html)
1095  {
1096  $this->header_html = $header_html;
1097  }
1098 
1102  public function getHeaderHtmlSpacing()
1103  {
1105  }
1106 
1111  {
1112  $this->header_html_spacing = $header_html_spacing;
1113  }
1114 
1118  public function isHeaderHtmlLine()
1119  {
1120  return $this->header_html_line;
1121  }
1122 
1127  {
1128  $this->header_html_line = $header_html_line;
1129  }
1130 
1131  protected function getFooterArgument()
1132  {
1133  $footer_value = $this->getFooterType();
1134  if ($footer_value == ilPDFGenerationConstants::FOOTER_TEXT) {
1135  $this->config[] = 'footer-left "' . $this->getFooterTextLeft() . '"';
1136  $this->config[] = 'footer-center "' . $this->getFooterTextCenter() . '"';
1137  $this->config[] = 'footer-right "' . $this->getFooterTextRight() . '"';
1138  if ($this->getFooterTextSpacing() != '') {
1139  $this->config[] = 'footer-spacing ' . $this->getFooterTextSpacing();
1140  }
1141 
1142  if ($this->isFooterTextLine()) {
1143  $this->config[] = 'footer-line';
1144  }
1145  } else {
1146  if ($footer_value == ilPDFGenerationConstants::FOOTER_HTML) {
1147  $this->config[] = 'footer-html "' . $this->getFooterHtml() . '"';
1148 
1149  if ($this->getFooterHtmlSpacing() != '') {
1150  $this->config[] = 'footer-spacing ' . $this->getFooterHtmlSpacing();
1151  }
1152  if ($this->isFooterHtmlLine()) {
1153  $this->config[] = 'footer-line';
1154  }
1155  }
1156  }
1157  }
1158 
1159  protected function getDebugArgument()
1160  {
1161  if (self::ENABLE_QUIET) {
1162  $this->config[] = 'quiet';
1163  }
1164  }
1165 
1166  protected function getSessionObject()
1167  {
1168  $this->config[] = 'cookie "PHPSESSID" "' . session_id() . '"';
1169  $this->config[] = 'cookie "ilClientId" "' . CLIENT_ID . '"';
1170  }
1171 
1175  protected function getSavedDefaultBinaryPath(){
1176  $settings = new ilSetting('wkhtmltopdfrenderer');
1177  $path = $settings->get('path');
1178  if( ! is_bool($path) && $path != null && $path != ''){
1179  return $path;
1180  }
1181  return '';
1182  }
1183 }
setHeaderTextLine($header_text_line)
setRadioButtonSvg($radio_button_svg)
setJavascriptDelay($javascript_delay)
setOverwriteDefaultFont($overwrite_default_font)
setHeaderHtmlSpacing($header_html_spacing)
__construct($config=null)
ilWkhtmlToPdfConfig constructor.
setFooterTextLine($footer_text_line)
setFooterHtmlLine($footer_html_line)
setFooterHtmlSpacing($footer_html_spacing)
setFooterTextCenter($footer_text_center)
setPrintMediaType($print_media_type)
setHeaderTextRight($header_text_right)
setFooterTextLeft($footer_text_left)
setRadioButtonCheckedSvg($radio_button_checked_svg)
setUserStylesheet($user_stylesheet)
setHeaderHtmlLine($header_html_line)
setFooterTextRight($footer_text_right)
setKeyIfExists($function, $key, $config)
getOverwriteDefaultFont($renderStyle=false)
setHeaderTextLeft($header_text_left)
setFooterTextSpacing($footer_text_spacing)
setCheckboxCheckedSvg($checkbox_checked_svg)
setHeaderTextSpacing($header_text_spacing)
setHeaderTextCenter($header_text_center)