24 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> 27 <body>$contentHtml</body> 36 private static function makeHtmlDocument($contentHtml, $styleHtml)
38 if(!is_string($contentHtml) || !strlen(trim($contentHtml)))
43 $html = self::buildHtmlDocument($contentHtml, $styleHtml);
46 if(!@$dom->loadHTML(
$html))
51 $invalid_elements =
array();
53 $script_elements = $dom->getElementsByTagName(
'script');
54 foreach($script_elements as $elm)
56 $invalid_elements[] = $elm;
59 foreach($invalid_elements as $elm)
61 $elm->parentNode->removeChild($elm);
65 $domX =
new DomXPath($dom);
66 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)
77 $uid =
'img_src_' . uniqid();
78 $src = $elm->getAttribute(
'src');
80 $elm->setAttribute(
'src', $uid);
82 $img_src_map[$uid] = $src;
85 $cleaned_html = $dom->saveHTML();
87 foreach($img_src_map as $uid => $src)
89 $cleaned_html = str_replace($uid, $src, $cleaned_html);
102 $pdf_output = self::preprocessHTML($pdf_output);
109 require_once
'./Services/PDFGeneration/classes/class.ilPDFGeneration.php';
112 $job->setAutoPageBreak(
true)
113 ->setCreator(
'ILIAS Test')
115 ->setMarginLeft(
'20')
116 ->setMarginRight(
'20')
118 ->setMarginBottom(
'20')
119 ->setOutputMode($output_mode)
120 ->addPage($pdf_output);
127 $html = self::makeHtmlDocument(
$html,
'<style>'.self::getCssContent().
'</style>');
132 protected static function getTemplatePath($a_filename, $module_path =
'Modules/Test/')
135 include_once
"Services/Style/System/classes/class.ilStyleDefinition.php";
136 if (ilStyleDefinition::getCurrentSkin() !=
"default")
138 $fname =
"./Customizing/global/skin/".
139 ilStyleDefinition::getCurrentSkin().
"/".$module_path.basename($a_filename);
142 if($fname ==
"" || !file_exists($fname))
144 $fname =
"./".$module_path.
"templates/default/".basename($a_filename);
151 $cssContent = file_get_contents( self::getTemplatePath(
'delos.css',
'') );
152 $cssContent .= file_get_contents( self::getTemplatePath(
'test_pdf.css') );
Class ilTestPDFGenerator.
static buildHtmlDocument($contentHtml, $styleHtml)
static preprocessHTML($html)
Create styles array
The data for the language used.
Class ilPDFGenerationJob.
static generatePDF($pdf_output, $output_mode, $filename=null)
const PDF_OUTPUT_DOWNLOAD
static doJob(ilPDFGenerationJob $job)
static getTemplatePath($a_filename, $module_path='Modules/Test/')