-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_pdf.php
73 lines (65 loc) · 2.08 KB
/
print_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
<?php
function generateRow(){
$contents = '';
include_once('connection.php');
$sql = "SELECT * FROM members";
//use for MySQLi OOP
$query = $conn->query($sql);
while($row = $query->fetch_assoc()){
$contents .= "
<tr>
<td>".$row['id']."</td>
<td>".$row['firstname']."</td>
<td>".$row['lastname']."</td>
<td>".$row['address']."</td>
</tr>
";
}
////////////////
//use for MySQLi Procedural
// $query = mysqli_query($conn, $sql);
// while($row = mysqli_fetch_assoc($query)){
// $contents .= "
// <tr>
// <td>".$row['id']."</td>
// <td>".$row['firstname']."</td>
// <td>".$row['lastname']."</td>
// <td>".$row['address']."</td>
// </tr>
// ";
// }
////////////////
return $contents;
}
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle("Generated PDF using TCPDF");
$pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont('helvetica');
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetAutoPageBreak(TRUE, 10);
$pdf->SetFont('helvetica', '', 11);
$pdf->AddPage();
$content = '';
$content .= '
<h2 align="center">Generated PDF using TCPDF</h2>
<h4>Members Table</h4>
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<th width="5%">ID</th>
<th width="20%">IP</th>
<th width="20%">Hostname</th>
<th width="55%">Windows</th>
</tr>
';
$content .= generateRow();
$content .= '</table>';
$pdf->writeHTML($content);
$pdf->Output('members.pdf', 'I');
?>