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);
72 $domX =
new DomXPath($dom);
73 foreach($domX->query(
"//*[contains(@class, 'ilNoDisplay')]") as $node)
75 $node->parentNode->removeChild($node);
78 $dom->encoding =
'UTF-8';
80 $img_src_map = array();
81 foreach($dom->getElementsByTagName(
'img') as $elm)
84 $uid =
'img_src_' . uniqid();
85 $src = $elm->getAttribute(
'src');
87 $elm->setAttribute(
'src', $uid);
89 $img_src_map[$uid] = $src;
92 $cleaned_html = $dom->saveHTML();
94 foreach($img_src_map as $uid => $src)
96 $cleaned_html = str_replace($uid, $src, $cleaned_html);
104 return '<?xml encoding="UTF-8">'.$cleaned_html;
109 $pdf_output = self::preprocessHTML($pdf_output);
116 require_once
'./Services/PDFGeneration/classes/class.ilPDFGeneration.php';
119 $job->setAutoPageBreak(
true)
120 ->setCreator(
'ILIAS Test')
122 ->setMarginLeft(
'20')
123 ->setMarginRight(
'20')
125 ->setMarginBottom(
'20')
126 ->setOutputMode($output_mode)
127 ->addPage($pdf_output);
134 $pdf_css_path = self::getTemplatePath(
'test_pdf.css');
135 $html = self::makeHtmlDocument(
$html,
'<style>'.file_get_contents($pdf_css_path).
'</style>');
142 $module_path =
"Modules/Test/";
145 include_once
"Services/Style/classes/class.ilStyleDefinition.php";
146 if (ilStyleDefinition::getCurrentSkin() !=
"default")
148 $fname =
"./Customizing/global/skin/".
149 ilStyleDefinition::getCurrentSkin().
"/".$module_path.basename($a_filename);
152 if($fname ==
"" || !file_exists($fname))
154 $fname =
"./".$module_path.
"templates/default/".basename($a_filename);
Class ilTestPDFGenerator.
static buildHtmlDocument($contentHtml, $styleHtml)
static preprocessHTML($html)
static getTemplatePath($a_filename)
Class ilPDFGenerationJob.
static generatePDF($pdf_output, $output_mode, $filename=null)
const PDF_OUTPUT_DOWNLOAD
static doJob(ilPDFGenerationJob $job)