1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Platine PDF |
5
|
|
|
* |
6
|
|
|
* Platine PDF is the lightweight for generating PDF documents |
7
|
|
|
* |
8
|
|
|
* This content is released under the MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2020 Platine PDF |
11
|
|
|
* |
12
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
13
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
14
|
|
|
* in the Software without restriction, including without limitation the rights |
15
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
16
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
17
|
|
|
* furnished to do so, subject to the following conditions: |
18
|
|
|
* |
19
|
|
|
* The above copyright notice and this permission notice shall be included in all |
20
|
|
|
* copies or substantial portions of the Software. |
21
|
|
|
* |
22
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
23
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
24
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
25
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
26
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
27
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
28
|
|
|
* SOFTWARE. |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @file PDF.php |
33
|
|
|
* |
34
|
|
|
* The PDF main class. |
35
|
|
|
* |
36
|
|
|
* @package Platine\PDF |
37
|
|
|
* @author Platine Developers Team |
38
|
|
|
* @copyright Copyright (c) 2020 |
39
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
40
|
|
|
* @link https://www.platine-php.com |
41
|
|
|
* @version 1.0.0 |
42
|
|
|
* @filesource |
43
|
|
|
*/ |
44
|
|
|
|
45
|
|
|
declare(strict_types=1); |
46
|
|
|
|
47
|
|
|
namespace Platine\PDF; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @class PDF |
51
|
|
|
* @package Platine\PDF |
52
|
|
|
*/ |
53
|
|
|
class PDF |
54
|
|
|
{ |
55
|
|
|
/** |
56
|
|
|
* The content to use to generate PDF document |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
protected string $content = ''; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The PDF generated filename |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected string $filename = 'output.pdf'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The PDF document paper type like 'A4', 'A5', 'letter', etc. |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected string $format = 'A4'; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The PDF document orientation like 'portrait', 'landscape' |
75
|
|
|
* @var string |
76
|
|
|
*/ |
77
|
|
|
protected string $orientation = 'portrait'; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Create new instance |
81
|
|
|
* |
82
|
|
|
* @param PDFGeneratorInterface $generator |
83
|
|
|
*/ |
84
|
|
|
public function __construct(protected PDFGeneratorInterface $generator) |
85
|
|
|
{ |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return the generator |
90
|
|
|
* @return PDFGeneratorInterface |
91
|
|
|
*/ |
92
|
|
|
public function getGenerator(): PDFGeneratorInterface |
93
|
|
|
{ |
94
|
|
|
return $this->generator; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the generator |
99
|
|
|
* @param PDFGeneratorInterface $generator |
100
|
|
|
* @return $this |
101
|
|
|
*/ |
102
|
|
|
public function setGenerator(PDFGeneratorInterface $generator): self |
103
|
|
|
{ |
104
|
|
|
$this->generator = $generator; |
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Return the content |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getContent(): string |
113
|
|
|
{ |
114
|
|
|
return $this->content; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Return the filename |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
|
|
public function getFilename(): string |
122
|
|
|
{ |
123
|
|
|
return $this->filename; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Return the format |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getFormat(): string |
131
|
|
|
{ |
132
|
|
|
return $this->format; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Return the orientation |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
public function getOrientation(): string |
140
|
|
|
{ |
141
|
|
|
return $this->orientation; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Set the content |
146
|
|
|
* @param string $content |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
|
|
public function setContent(string $content): self |
150
|
|
|
{ |
151
|
|
|
$this->content = $content; |
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Set the filename |
157
|
|
|
* @param string $filename |
158
|
|
|
* @return $this |
159
|
|
|
*/ |
160
|
|
|
public function setFilename(string $filename): self |
161
|
|
|
{ |
162
|
|
|
$this->filename = $filename; |
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set the format |
168
|
|
|
* @param string $format |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
|
|
public function setFormat(string $format): self |
172
|
|
|
{ |
173
|
|
|
$this->format = $format; |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Set the orientation |
179
|
|
|
* @param string $orientation |
180
|
|
|
* @return $this |
181
|
|
|
*/ |
182
|
|
|
public function setOrientation(string $orientation): self |
183
|
|
|
{ |
184
|
|
|
$this->orientation = $orientation; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Generate the PDF document |
190
|
|
|
* @return $this |
191
|
|
|
*/ |
192
|
|
|
public function generate(): self |
193
|
|
|
{ |
194
|
|
|
$this->generator->generate( |
195
|
|
|
$this->content, |
196
|
|
|
$this->filename, |
197
|
|
|
$this->format, |
198
|
|
|
$this->orientation |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Return the content of the generated PDF document as string |
206
|
|
|
* @return string |
207
|
|
|
*/ |
208
|
|
|
public function raw(): string |
209
|
|
|
{ |
210
|
|
|
return $this->generator->raw(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Download the generated PDF document |
215
|
|
|
* @return void |
216
|
|
|
*/ |
217
|
|
|
public function download(): void |
218
|
|
|
{ |
219
|
|
|
$this->generator->download(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Save the content of the generated PDF document on |
224
|
|
|
* the file system, etc. |
225
|
|
|
* @return void |
226
|
|
|
*/ |
227
|
|
|
public function save(): void |
228
|
|
|
{ |
229
|
|
|
$this->generator->save(); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|