-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoice.php
More file actions
116 lines (109 loc) · 2.91 KB
/
invoice.php
File metadata and controls
116 lines (109 loc) · 2.91 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require __DIR__ . '/vendor/autoload.php';
use Mpdf\Mpdf;
use Mpdf\Config\ConfigVariables;
use Mpdf\Config\FontVariables;
$html = <<<HTML
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<title>صورتحساب</title>
<style>
body {
font-family: 'XP Ziba';
direction: rtl;
text-align: right;
line-height: 1.6;
}
h1 {
color: #2E86C1;
font-size: 24px;
}
p {
font-size: 16px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
font-size: 15px;
}
th, td {
border: 1px solid #aaa;
padding: 10px;
}
th {
background-color: #f2f2f2;
}
tfoot td {
font-weight: bold;
}
</style>
</head>
<body>
<h1>صورتحساب فروش</h1>
<p><strong>تاریخ:</strong> ۱۴۰۳/۰۳/۱۳</p>
<p><strong>مشتری:</strong> علی رضایی</p>
<table>
<thead>
<tr>
<th>کالا</th>
<th>تعداد</th>
<th>قیمت واحد</th>
<th>جمع</th>
</tr>
</thead>
<tbody>
<tr>
<td>کتاب ریاضی</td>
<td>۲</td>
<td>۵۰۰٬۰۰۰ ریال</td>
<td>۱٬۰۰۰٬۰۰۰ ریال</td>
</tr>
<tr>
<td>دفتر مشق</td>
<td>۵</td>
<td>۱۰۰٬۰۰۰ ریال</td>
<td>۵۰۰٬۰۰۰ ریال</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" style="text-align: left;">مبلغ کل</td>
<td>۱٬۵۰۰٬۰۰۰ ریال</td>
</tr>
</tfoot>
</table>
</body>
</html>
HTML;
$config = (new ConfigVariables())->getDefaults();
$fontDirs = $config['fontDir'];
$fontConfig = (new FontVariables())->getDefaults();
$fontData = $fontConfig['fontdata'];
$mpdf = new Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 10,
'margin_bottom' => 10,
'fontDir' => array_merge($fontDirs, [__DIR__ . '/fonts']),
'fontdata' => $fontData + [
'XP Ziba' => [
'R' => 'XP Ziba.ttf',
'B' => 'XP Ziba Bd.ttf',
],
],
'default_font' => 'XP Ziba',
'default_direction' => 'rtl',
]);
$mpdf->showImageErrors = true;
$mpdf->debugfonts = true;
// $mpdf->autoLangToFont = true;
$mpdf->autoScriptToLang = true;
$mpdf->WriteHTML($html);
// $mpdf->Output('invoice.pdf', \Mpdf\Output\Destination::INLINE);
$mpdf->Output(__DIR__ . '/invoice.pdf', \Mpdf\Output\Destination::FILE);
print "PDF created successfully: " . __DIR__ . '/invoice.pdf' . "\n";