4require_once 
'./Services/PDFGeneration/classes/factory/class.ilHtmlToPdfTransformerFactory.php';
 
    5require_once 
'./Services/PDFGeneration/classes/class.ilPDFGeneratorUtils.php';
 
   29                                        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> 
   32                                <body>$contentHtml</body> 
   41    private static function makeHtmlDocument($contentHtml, $styleHtml)
 
   43        if (!is_string($contentHtml) || !strlen(trim($contentHtml))) {
 
   49        $dom = 
new DOMDocument(
"1.0", 
"utf-8");
 
   50        if (!@$dom->loadHTML(
$html)) {
 
   54        $invalid_elements = array();
 
   56        $script_elements = $dom->getElementsByTagName(
'script');
 
   57        foreach ($script_elements as $elm) {
 
   58            $invalid_elements[] = $elm;
 
   61        foreach ($invalid_elements as $elm) {
 
   62            $elm->parentNode->removeChild($elm);
 
   66        $domX = 
new DomXPath($dom);
 
   67        foreach ($domX->query(
"//*[contains(@class, 'noprint')]") as $node) {
 
   68            $node->parentNode->removeChild($node);
 
   71        $dom->encoding = 
'UTF-8';
 
   73        $img_src_map = array();
 
   74        foreach ($dom->getElementsByTagName(
'img') as $elm) {
 
   76            $uid = 
'img_src_' . uniqid();
 
   77            $src = $elm->getAttribute(
'src');
 
   79            $elm->setAttribute(
'src', $uid);
 
   81            $img_src_map[$uid] = $src;
 
   84        $cleaned_html = $dom->saveHTML();
 
   86        foreach ($img_src_map as $uid => $src) {
 
   87            $cleaned_html = str_replace($uid, $src, $cleaned_html);
 
  105        return $pdf_factory->deliverPDFFromHTMLString($pdf_output, 
$filename, $output_mode, self::service, $purpose);
 
  110        $html = self::makeHtmlDocument(
$html, 
'<style>' . self::getCssContent() . 
'</style>');
 
  115    protected static function getTemplatePath($a_filename, $module_path = 
'Modules/Test/')
 
  118        include_once 
"Services/Style/System/classes/class.ilStyleDefinition.php";
 
  120            $fname = 
"./Customizing/global/skin/" .
 
  124        if ($fname == 
"" || !file_exists($fname)) {
 
  125            $fname = 
"./" . $module_path . 
"templates/default/" . basename($a_filename);
 
  132        $cssContent = file_get_contents(self::getTemplatePath(
'delos.css', 
''));
 
  133        $cssContent .= file_get_contents(self::getTemplatePath(
'test_pdf.css'));
 
An exception for terminatinating execution or to throw for unit testing.
static getCurrentSkin()
get the current skin
Class ilTestPDFGenerator.
static preprocessHTML($html)
static getTemplatePath($a_filename, $module_path='Modules/Test/')
static generatePDF($pdf_output, $output_mode, $filename=null, $purpose=null)
const PDF_OUTPUT_DOWNLOAD
static buildHtmlDocument($contentHtml, $styleHtml)