-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.php
77 lines (63 loc) · 2.16 KB
/
pdf.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
session_start();
//Includes
require("includes/mpdf60/mpdf.php");
require("includes/parsedown.php");
//Initiate vars
$pdf=new mPDF('','A4',10,'Arial');
$line_number = 1;
$filename = "paprs - " . strtolower($_POST['paprs_Title']) . " - " .date("Ymd") . ".pdf";
$text = '';
$total = '';
//CSS Styles
$text .= "<link rel='stylesheet' href='css/pdf.css' type='text/css' />";
//Paper details
$text .= "<div class='heading'>";
$text .= "<h1>" . $_POST['paprs_Title'] . "</h1>";
if (!empty($_POST['paprs_Author'])){
$text .= "<h2><span class='accent'>Prepared by:</span> " . $_POST['paprs_Author'] . "</h2>";
}
if (!empty($_POST['paprs_Time'])){
$text .= "<h3><span class='accent'>Allowed time:</span> " . $_POST['paprs_Time'] . "</h3>";
}
$text .= "</div>";
$text .= "<hr/>";
//Questions
$text .= "<div class='body'>";
foreach ($_POST['paprs_Questions'] as $question)
{
//Define variables
$parsedown = new Parsedown();
$line_amount = $question['lines'];
$question_text = mb_convert_encoding($question['text'],'UTF-8');
$question_points = $question['points'];
//Construct question
$text .= "<div class='question'>";
$text .= "<div class='col_1'><strong>" . $line_number . "</strong></div>";
$text .= "<div class='col_10'>";
$text .= "<div class='text'>" . $parsedown->text($question_text) . "</div>";
//Create answer lines
$x = 1;
$text .= "<div class='lines'>";
while ( $x <= $line_amount) {
$text .= "<div class='row'></div>";
$x++;
};
$text .= "</div></div><!-- End of .lines -->";
$text .= "<div class='col_1'>[" .$question_points . "]</div>";
$text .= "</div><!-- End of .question -->";
$text .= "</div>";
//Increment line number
$line_number++;
//Sum the total points
$total += $question['points'];
};
$text .= "<div class='total'>[Total: " . $total . "]</div>";
$text .= "</div><!-- End of .body -->";
//Write the PDF
$pdf->SetTitle($_POST['paprs_Title']);
$pdf->SetAuthor($_POST['paprs_Author']);
$pdf->WriteHTML($text);
$pdf->Output($filename,I);
exit;
?>