ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilWkhtmlToPdfRenderer Class Reference
+ Inheritance diagram for ilWkhtmlToPdfRenderer:
+ Collaboration diagram for ilWkhtmlToPdfRenderer:

Public Member Functions

 __construct ($phpunit=false)
 ilWkhtmlToPdfRenderer constructor. More...
 
 addConfigElementsToForm (ilPropertyFormGUI $form, $service, $purpose)
 
 populateConfigElementsInForm (ilPropertyFormGUI $form, $service, $purpose, $config)
 
 validateConfigInForm (ilPropertyFormGUI $form, $service, $purpose)
 
 getConfigFromForm (ilPropertyFormGUI $form, $service, $purpose)
 
 getDefaultConfig ($service, $purpose)
 
 generatePDF ($service, $purpose, $config, $job)
 
 getHtmlTempName ()
 
 createPDFFileFromHTMLFile ($a_path_to_file, $config, $job)
 
 getPdfTempName ()
 
 prepareGenerationRequest ($service, $purpose)
 
- Public Member Functions inherited from ilRendererConfig
 addConfigElementsToForm (\ilPropertyFormGUI $form, $service, $purpose)
 
 populateConfigElementsInForm (\ilPropertyFormGUI $form, $service, $purpose, $config)
 
 validateConfigInForm (\ilPropertyFormGUI $form, $service, $purpose)
 
 getConfigFromForm (\ilPropertyFormGUI $form, $service, $purpose)
 

Protected Member Functions

 setLanguage ($lng)
 
 getTempFileName ($file_type)
 
 runCommandLine ($a_path_to_file, $a_target, $config)
 
 redirectLog ()
 
 appendDefaultFontStyle ($a_path_to_file, $config)
 

Protected Attributes

 $config
 
 $lng
 

Static Protected Attributes

static $instance = null
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilWkhtmlToPdfRenderer::__construct (   $phpunit = false)

ilWkhtmlToPdfRenderer constructor.

Parameters
bool$phpunit

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

References $DIC, and setLanguage().

17  {
18  if (!$phpunit) {
19  global $DIC;
20  $this->setLanguage($DIC['lng']);
21  }
22  }
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ addConfigElementsToForm()

ilWkhtmlToPdfRenderer::addConfigElementsToForm ( ilPropertyFormGUI  $form,
  $service,
  $purpose 
)
Parameters
ilPropertyFormGUI$form
string$service
string$purpose

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

38  {
39  $gui = new ilWkhtmlToPdfConfigFormGUI();
40  $gui->addConfigForm($form);
41  }

◆ appendDefaultFontStyle()

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

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

References $config.

Referenced by runCommandLine().

191  {
192  $backupStyle = $config->getOverwriteDefaultFont(true);
193  $originalFile = file_get_contents($a_path_to_file) . $backupStyle;
194  file_put_contents($a_path_to_file, $originalFile);
195  }
+ Here is the caller graph for this function:

◆ createPDFFileFromHTMLFile()

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

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

References $config, and runCommandLine().

Referenced by generatePDF().

127  {
128  if (is_array($a_path_to_file)) {
129  $files_list_as_string = ' ';
130  foreach ($a_path_to_file as $file) {
131  if (file_exists($file)) {
132  $files_list_as_string .= ' ' . $files_list_as_string;
133  }
134  }
135  $this->runCommandLine($files_list_as_string, $job->getFilename(), $config);
136  } else {
137  if (file_exists($a_path_to_file)) {
138  $this->runCommandLine($a_path_to_file, $job->getFilename(), $config);
139  }
140  }
141  }
runCommandLine($a_path_to_file, $a_target, $config)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generatePDF()

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

Implements ilPDFRenderer.

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

References $config, createPDFFileFromHTMLFile(), and getHtmlTempName().

98  {
99  $html_file = $this->getHtmlTempName();
100  file_put_contents($html_file, implode('', $job->getPages()));
101  $this->createPDFFileFromHTMLFile($html_file, $config, $job);
102  }
createPDFFileFromHTMLFile($a_path_to_file, $config, $job)
+ Here is the call graph for this function:

◆ getConfigFromForm()

ilWkhtmlToPdfRenderer::getConfigFromForm ( ilPropertyFormGUI  $form,
  $service,
  $purpose 
)
Parameters
ilPropertyFormGUI$form
string$service
string$purpose
Returns
array

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

75  {
76  $gui = new ilWkhtmlToPdfConfigFormGUI();
77  return $gui->getConfigFromForm($form);
78  }

◆ getDefaultConfig()

ilWkhtmlToPdfRenderer::getDefaultConfig (   $service,
  $purpose 
)
Parameters
string$service
string$purpose
Returns
ilWkhtmlToPdfConfig

Implements ilRendererConfig.

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

References $config.

◆ getHtmlTempName()

ilWkhtmlToPdfRenderer::getHtmlTempName ( )
Returns
string

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

References getTempFileName().

Referenced by generatePDF().

108  {
109  return $this->getTempFileName('html');
110  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPdfTempName()

ilWkhtmlToPdfRenderer::getPdfTempName ( )
Returns
string

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

References getTempFileName().

Referenced by runCommandLine().

174  {
175  return $this->getTempFileName('pdf');
176  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTempFileName()

ilWkhtmlToPdfRenderer::getTempFileName (   $file_type)
protected
Parameters
$file_type
Returns
string

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

References ilUtil\ilTempnam().

Referenced by getHtmlTempName(), and getPdfTempName().

117  {
118  return ilUtil::ilTempnam() . '.' . $file_type;
119  }
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ populateConfigElementsInForm()

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

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

References $config.

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

◆ prepareGenerationRequest()

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

Implements ilPDFRenderer.

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

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

202  {
204  ->init(ilMathJax::PURPOSE_PDF)
205  ->setRendering(ilMathJax::RENDER_SVG_AS_XML_EMBED);
206  }
const PURPOSE_PDF
static getInstance()
Singleton: get instance.
const RENDER_SVG_AS_XML_EMBED
+ Here is the call graph for this function:

◆ redirectLog()

ilWkhtmlToPdfRenderer::redirectLog ( )
protected
Returns
string

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

Referenced by runCommandLine().

182  {
183  return $redirect_log = ' 2>&1 ';
184  }
+ Here is the caller graph for this function:

◆ runCommandLine()

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

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

References $config, $DIC, $log, appendDefaultFontStyle(), ilUtil\execQuoted(), getPdfTempName(), and redirectLog().

Referenced by createPDFFileFromHTMLFile().

149  {
150  global $DIC;
151  $log = $DIC['ilLog'];
153  $temp_file = $this->getPdfTempName();
154  $args = $config->getCommandLineConfig() . ' ' . $a_path_to_file . ' ' . $temp_file . $this->redirectLog();
155  $this->appendDefaultFontStyle($a_path_to_file, $config);
156  $return_value = ilUtil::execQuoted($config->getWKHTMLToPdfDefaultPath(), $args);
157  $log->debug('ilWebkitHtmlToPdfTransformer command line config: ' . $args);
158  foreach ($return_value as $key => $value) {
159  $log->debug('ilWebkitHtmlToPdfTransformer return value line ' . $key . ' : ' . $value);
160  }
161  if (file_exists($temp_file)) {
162  $log->debug('ilWebkitHtmlToPdfTransformer file exists: ' . $temp_file . ' file size is :' . filesize($temp_file) . ' bytes, will be renamed to ' . $a_target);
163  rename($temp_file, $a_target);
164  } else {
165  $log->info('ilWebkitHtmlToPdfTransformer error: ' . print_r($return_value, true));
166  }
167  unlink($a_path_to_file);
168  }
$log
Definition: result.php:15
global $DIC
Definition: goto.php:24
static execQuoted($cmd, $args=null)
exec command and fix spaces on windows
appendDefaultFontStyle($a_path_to_file, $config)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLanguage()

ilWkhtmlToPdfRenderer::setLanguage (   $lng)
protected
Parameters
$lng

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

References $lng.

Referenced by __construct().

28  {
29  $this->lng = $lng;
30  }
+ Here is the caller graph for this function:

◆ validateConfigInForm()

ilWkhtmlToPdfRenderer::validateConfigInForm ( ilPropertyFormGUI  $form,
  $service,
  $purpose 
)
Parameters
ilPropertyFormGUI$form
string$service
string$purpose
Returns
bool

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

63  {
64  $gui = new ilWkhtmlToPdfConfigFormGUI();
65  return $gui->validateForm();
66  }

Field Documentation

◆ $config

◆ $instance

ilWkhtmlToPdfRenderer::$instance = null
staticprotected

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

◆ $lng

ilWkhtmlToPdfRenderer::$lng
protected

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

Referenced by setLanguage().


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