forked from riverspirit/Card-Generator
-
Notifications
You must be signed in to change notification settings - Fork 45
/
generate.php
executable file
·46 lines (34 loc) · 1.15 KB
/
generate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require_once("vendor/autoload.php");
require_once("config.php");
use Dompdf\Dompdf;
use Dompdf\Options;
function resolveDependency($html) {
$html = str_replace('src="../../', 'src="'. $GLOBALS['RESOURCE'], $html);
$html = str_replace('src="../', 'src="'. $GLOBALS['RESOURCE'], $html);
return $html;
}
function getCSSFromHTML($html) {
$css = '';
preg_match_all("/(?<=link[\s]rel=\"stylesheet\"[\s]href=\"[.][.]\/css\/)(.*?)\"/", $html, $fmatches);
foreach($fmatches as $key => $m) {
if($key % 2 == 1) {
$css .= file_get_contents('./css/' . $m[0]);
}
}
return $css;
}
if ( isset( $_POST[ "html" ] ) && isset( $_POST[ "html2" ] ) ) {
$frontPage = resolveDependency(stripslashes( $_POST[ "html" ] ));
$backPage = resolveDependency(stripslashes( $_POST[ "html2" ]) );
$frontPageCSS = getCSSFromHTML($frontPage);
$backPageCSS = getCSSFromHTML($backPage);
$mpdf = new mPDF('utf-8', array(93, 54.87), 0, '', 0, 0, 0, 0, 0, 0);
$mpdf->WriteHTML($frontPageCSS, 1);
$mpdf->WriteHTML($frontPage, 0);
$mpdf->WriteHTML('<pagebreak>', 2);
$mpdf->WriteHTML($backPageCSS, 1);
$mpdf->WriteHTML($backPage, 0);
$mpdf->Output('card.pdf', 'I');
exit( 0 );
}