ILIAS  release_8 Revision v8.24
ilWkhtmlToPdfRenderer Class Reference
+ Inheritance diagram for ilWkhtmlToPdfRenderer:
+ Collaboration diagram for ilWkhtmlToPdfRenderer:

Public Member Functions

 __construct (bool $phpunit=false)
 
 addConfigElementsToForm (ilPropertyFormGUI $form, string $service, string $purpose)
 
 populateConfigElementsInForm (ilPropertyFormGUI $form, string $service, string $purpose, $config)
 
 validateConfigInForm (ilPropertyFormGUI $form, string $service, string $purpose)
 
 getConfigFromForm (ilPropertyFormGUI $form, string $service, string $purpose)
 
 getDefaultConfig (string $service, string $purpose)
 
 generatePDF (string $service, string $purpose, $config, ilPDFGenerationJob $job)
 
 getHtmlTempName ()
 
 createPDFFileFromHTMLFile (string $a_path_to_file, $config, ilPDFGenerationJob $job)
 
 getPdfTempName ()
 
 prepareGenerationRequest (string $service, string $purpose)
 Prepare the content processing at the beginning of a PDF generation request Should be used to initialize the processing of latex code The PDF renderers require different image formats generated by the MathJax service. More...
 
- Public Member Functions inherited from ilRendererConfig
 addConfigElementsToForm (ilPropertyFormGUI $form, string $service, string $purpose)
 
 populateConfigElementsInForm (ilPropertyFormGUI $form, string $service, string $purpose, array $config)
 
 validateConfigInForm (ilPropertyFormGUI $form, string $service, string $purpose)
 
 getConfigFromForm (ilPropertyFormGUI $form, string $service, string $purpose)
 
 getDefaultConfig (string $service, string $purpose)
 
- Public Member Functions inherited from ilPDFRenderer
 generatePDF (string $service, string $purpose, array $config, ilPDFGenerationJob $job)
 
 prepareGenerationRequest (string $service, string $purpose)
 Prepare the content processing at the beginning of a PDF generation request Should be used to initialize the processing of latex code The PDF renderers require different image formats generated by the MathJax service. More...
 

Protected Member Functions

 setLanguage (ilLanguage $lng)
 
 getTempFileName (string $file_type)
 
 runCommandLine (string $a_path_to_file, string $a_target, $config)
 
 redirectLog ()
 
 appendDefaultFontStyle (string $a_path_to_file, ilWkhtmlToPdfConfig $config)
 
 fixIconSizeForPatchedQt (string $a_path_to_file)
 Fix for an issue of WkhtmlToPdf with patched QT Without a fixed width the icons would be distorted and corrupt the hole PDF. More...
 
 checkReturnValueFromCommandLine (array $return_value, string $temp_file, string $a_target)
 

Protected Attributes

ilWkhtmlToPdfConfig $config
 
ilLanguage $lng
 
ilLogger $log
 

Detailed Description

Deprecated:

Definition at line 24 of file class.ilWkhtmlToPdfRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ilWkhtmlToPdfRenderer::__construct ( bool  $phpunit = false)

Definition at line 30 of file class.ilWkhtmlToPdfRenderer.php.

31 {
32 if (!$phpunit) {
33 global $DIC;
34 $this->setLanguage($DIC->language());
35 $this->log = $DIC->logger()->root();
36 }
37 }
global $DIC
Definition: feed.php:28

References $DIC, and setLanguage().

+ Here is the call graph for this function:

Member Function Documentation

◆ addConfigElementsToForm()

ilWkhtmlToPdfRenderer::addConfigElementsToForm ( ilPropertyFormGUI  $form,
string  $service,
string  $purpose 
)
Parameters
ilPropertyFormGUI$formThe config form for the administration
string$serviceService Title
string$purposePurpose Title
Returns
void

Implements ilRendererConfig.

Definition at line 44 of file class.ilWkhtmlToPdfRenderer.php.

44 : void
45 {
46 $gui = new ilWkhtmlToPdfConfigFormGUI();
47 $gui->addConfigForm($form);
48 }

◆ appendDefaultFontStyle()

ilWkhtmlToPdfRenderer::appendDefaultFontStyle ( string  $a_path_to_file,
ilWkhtmlToPdfConfig  $config 
)
protected

Definition at line 122 of file class.ilWkhtmlToPdfRenderer.php.

122 : void
123 {
124 $backupStyle = $config->getOverwriteDefaultFont(true);
125 $originalFile = file_get_contents($a_path_to_file) . $backupStyle;
126 file_put_contents($a_path_to_file, $originalFile);
127 }
getOverwriteDefaultFont(bool $renderStyle=false)

References $config, and ilWkhtmlToPdfConfig\getOverwriteDefaultFont().

Referenced by runCommandLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkReturnValueFromCommandLine()

ilWkhtmlToPdfRenderer::checkReturnValueFromCommandLine ( array  $return_value,
string  $temp_file,
string  $a_target 
)
protected

Definition at line 149 of file class.ilWkhtmlToPdfRenderer.php.

149 : void
150 {
151 foreach ($return_value as $key => $value) {
152 $this->log->debug('ilWebkitHtmlToPdfTransformer return value line ' . $key . ' : ' . $value);
153 }
154 if (file_exists($temp_file)) {
155 $this->log->debug('ilWebkitHtmlToPdfTransformer file exists: ' . $temp_file . ' file size is :' . filesize($temp_file) . ' bytes, will be renamed to ' . $a_target);
156 rename($temp_file, $a_target);
157 } else {
158 $this->log->info('ilWebkitHtmlToPdfTransformer error: ' . print_r($return_value, true));
159 }
160 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

Referenced by runCommandLine().

+ Here is the caller graph for this function:

◆ createPDFFileFromHTMLFile()

ilWkhtmlToPdfRenderer::createPDFFileFromHTMLFile ( string  $a_path_to_file,
  $config,
ilPDFGenerationJob  $job 
)

Definition at line 94 of file class.ilWkhtmlToPdfRenderer.php.

94 : void
95 {
96 $this->runCommandLine($a_path_to_file, $job->getFilename(), $config);
97 }
runCommandLine(string $a_path_to_file, string $a_target, $config)

References $config, ilPDFGenerationJob\getFilename(), and runCommandLine().

Referenced by generatePDF().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixIconSizeForPatchedQt()

ilWkhtmlToPdfRenderer::fixIconSizeForPatchedQt ( string  $a_path_to_file)
protected

Fix for an issue of WkhtmlToPdf with patched QT Without a fixed width the icons would be distorted and corrupt the hole PDF.

See also
https://mantis.ilias.de/view.php?id=36506

Definition at line 134 of file class.ilWkhtmlToPdfRenderer.php.

134 : void
135 {
136 $style = '<style>div.questionPrintview img.small {height: 20px; width: 20px;}</style>';
137 $originalFile = file_get_contents($a_path_to_file) . $style;
138 file_put_contents($a_path_to_file, $originalFile);
139 }

Referenced by runCommandLine().

+ Here is the caller graph for this function:

◆ generatePDF()

ilWkhtmlToPdfRenderer::generatePDF ( string  $service,
string  $purpose,
  $config,
ilPDFGenerationJob  $job 
)

Definition at line 75 of file class.ilWkhtmlToPdfRenderer.php.

75 : void
76 {
77 $html_file = $this->getHtmlTempName();
78 $pages = $job->getPages();
79
80 file_put_contents($html_file, implode('', $pages));
81 $this->createPDFFileFromHTMLFile($html_file, $config, $job);
82 }
createPDFFileFromHTMLFile(string $a_path_to_file, $config, ilPDFGenerationJob $job)

References $config, createPDFFileFromHTMLFile(), getHtmlTempName(), and ilPDFGenerationJob\getPages().

+ Here is the call graph for this function:

◆ getConfigFromForm()

ilWkhtmlToPdfRenderer::getConfigFromForm ( ilPropertyFormGUI  $form,
string  $service,
string  $purpose 
)
Parameters
ilPropertyFormGUI$formThe config form for the administration
string$serviceService Title
string$purposePurpose Title
Returns
array<string, mixed> KV-array with config

Implements ilRendererConfig.

Definition at line 63 of file class.ilWkhtmlToPdfRenderer.php.

63 : array
64 {
65 $gui = new ilWkhtmlToPdfConfigFormGUI();
66 return $gui->getConfigFromForm($form);
67 }

◆ getDefaultConfig()

ilWkhtmlToPdfRenderer::getDefaultConfig ( string  $service,
string  $purpose 
)
Parameters
string$serviceService Title
string$purposePurpose Title
Returns
mixed KV-array with config or an config instance

Implements ilRendererConfig.

Definition at line 69 of file class.ilWkhtmlToPdfRenderer.php.

References $config.

◆ getHtmlTempName()

ilWkhtmlToPdfRenderer::getHtmlTempName ( )

Definition at line 84 of file class.ilWkhtmlToPdfRenderer.php.

84 : string
85 {
86 return $this->getTempFileName('html');
87 }

References getTempFileName().

Referenced by generatePDF().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPdfTempName()

ilWkhtmlToPdfRenderer::getPdfTempName ( )

Definition at line 112 of file class.ilWkhtmlToPdfRenderer.php.

112 : string
113 {
114 return $this->getTempFileName('pdf');
115 }

References getTempFileName().

Referenced by runCommandLine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTempFileName()

ilWkhtmlToPdfRenderer::getTempFileName ( string  $file_type)
protected

Definition at line 89 of file class.ilWkhtmlToPdfRenderer.php.

89 : string
90 {
91 return ilFileUtils::ilTempnam() . '.' . $file_type;
92 }
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.

References ilFileUtils\ilTempnam().

Referenced by getHtmlTempName(), and getPdfTempName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ populateConfigElementsInForm()

ilWkhtmlToPdfRenderer::populateConfigElementsInForm ( ilPropertyFormGUI  $form,
string  $service,
string  $purpose,
  $config 
)

Definition at line 50 of file class.ilWkhtmlToPdfRenderer.php.

50 : void
51 {
52 $this->config = new ilWkhtmlToPdfConfig($config);
53 $gui = new ilWkhtmlToPdfConfigFormGUI();
54 $gui->populateForm($form, $this->config);
55 }

References $config.

◆ prepareGenerationRequest()

ilWkhtmlToPdfRenderer::prepareGenerationRequest ( string  $service,
string  $purpose 
)

Prepare the content processing at the beginning of a PDF generation request Should be used to initialize the processing of latex code The PDF renderers require different image formats generated by the MathJax service.

Parameters
string$service
string$purpose
Returns
void

Implements ilPDFRenderer.

Definition at line 142 of file class.ilWkhtmlToPdfRenderer.php.

142 : void
143 {
147 }
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
const PURPOSE_PDF
const RENDER_SVG_AS_XML_EMBED

References ilMathJax\getInstance(), ilMathJax\PURPOSE_PDF, and ilMathJax\RENDER_SVG_AS_XML_EMBED.

+ Here is the call graph for this function:

◆ redirectLog()

ilWkhtmlToPdfRenderer::redirectLog ( )
protected

Definition at line 117 of file class.ilWkhtmlToPdfRenderer.php.

117 : string
118 {
119 return ' 2>&1 ';
120 }

Referenced by runCommandLine().

+ Here is the caller graph for this function:

◆ runCommandLine()

ilWkhtmlToPdfRenderer::runCommandLine ( string  $a_path_to_file,
string  $a_target,
  $config 
)
protected

Definition at line 99 of file class.ilWkhtmlToPdfRenderer.php.

99 : void
100 {
101 $wkConfig = new ilWkhtmlToPdfConfig($config);
102 $temp_file = $this->getPdfTempName();
103 $args = $wkConfig->getCommandLineConfig() . ' ' . $a_path_to_file . ' ' . $temp_file . $this->redirectLog();
104 $this->appendDefaultFontStyle($a_path_to_file, $wkConfig);
105 $this->fixIconSizeForPatchedQt($a_path_to_file);
106 $return_value = ilShellUtil::execQuoted($wkConfig->getWKHTMLToPdfDefaultPath(), $args);
107 $this->log->debug('ilWebkitHtmlToPdfTransformer command line config: ' . $args);
108 $this->checkReturnValueFromCommandLine($return_value, $temp_file, $a_target);
109 unlink($a_path_to_file);
110 }
static execQuoted(string $cmd, ?string $args=null)
appendDefaultFontStyle(string $a_path_to_file, ilWkhtmlToPdfConfig $config)
fixIconSizeForPatchedQt(string $a_path_to_file)
Fix for an issue of WkhtmlToPdf with patched QT Without a fixed width the icons would be distorted an...
checkReturnValueFromCommandLine(array $return_value, string $temp_file, string $a_target)

References $config, appendDefaultFontStyle(), checkReturnValueFromCommandLine(), ilShellUtil\execQuoted(), fixIconSizeForPatchedQt(), getPdfTempName(), and redirectLog().

Referenced by createPDFFileFromHTMLFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLanguage()

ilWkhtmlToPdfRenderer::setLanguage ( ilLanguage  $lng)
protected

Definition at line 39 of file class.ilWkhtmlToPdfRenderer.php.

39 : void
40 {
41 $this->lng = $lng;
42 }

References $lng, and ILIAS\Repository\lng().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateConfigInForm()

ilWkhtmlToPdfRenderer::validateConfigInForm ( ilPropertyFormGUI  $form,
string  $service,
string  $purpose 
)
Parameters
ilPropertyFormGUI$formThe config form for the administration
string$serviceService Title
string$purposePurpose Title
Returns
bool True, if the form holds a valid config

Implements ilRendererConfig.

Definition at line 57 of file class.ilWkhtmlToPdfRenderer.php.

57 : bool
58 {
59 $gui = new ilWkhtmlToPdfConfigFormGUI();
60 return $gui->validateForm($form);
61 }

Field Documentation

◆ $config

◆ $lng

ilLanguage ilWkhtmlToPdfRenderer::$lng
protected

Definition at line 27 of file class.ilWkhtmlToPdfRenderer.php.

Referenced by setLanguage().

◆ $log

ilLogger ilWkhtmlToPdfRenderer::$log
protected

Definition at line 28 of file class.ilWkhtmlToPdfRenderer.php.


The documentation for this class was generated from the following file: