1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace JonnyW\PhantomJs\Http; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* PHP PhantomJs |
14
|
|
|
* |
15
|
|
|
* @author Jon Wenmoth <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class PdfRequest extends CaptureRequest |
18
|
|
|
implements PdfRequestInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Paper width |
22
|
|
|
* |
23
|
|
|
* @var int |
24
|
|
|
* @access protected |
25
|
|
|
*/ |
26
|
|
|
protected $paperWidth; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Paper height |
30
|
|
|
* |
31
|
|
|
* @var int |
32
|
|
|
* @access protected |
33
|
|
|
*/ |
34
|
|
|
protected $paperHeight; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Format |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
* @access protected |
41
|
|
|
*/ |
42
|
|
|
protected $format; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Orientation |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
* @access protected |
49
|
|
|
*/ |
50
|
|
|
protected $orientation; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Margin |
54
|
|
|
* |
55
|
|
|
* @var string|array |
56
|
|
|
* @access protected |
57
|
|
|
*/ |
58
|
|
|
protected $margin; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Repeating header |
62
|
|
|
* |
63
|
|
|
* @var array |
64
|
|
|
* @access protected |
65
|
|
|
*/ |
66
|
|
|
protected $header; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Repeating footer |
70
|
|
|
* |
71
|
|
|
* @var array |
72
|
|
|
* @access protected |
73
|
|
|
*/ |
74
|
|
|
protected $footer; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Internal constructor |
78
|
|
|
* |
79
|
|
|
* @access public |
80
|
|
|
* @param string $url (default: null) |
81
|
|
|
* @param string $method (default: RequestInterface::METHOD_GET) |
82
|
|
|
* @param int $timeout (default: 5000) |
83
|
|
|
* @return \JonnyW\PhantomJs\Http\CaptureRequest |
|
|
|
|
84
|
|
|
*/ |
85
|
29 |
|
public function __construct($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
86
|
|
|
{ |
87
|
29 |
|
parent::__construct($url, $method, $timeout); |
88
|
|
|
|
89
|
29 |
|
$this->paperWidth = ''; |
|
|
|
|
90
|
29 |
|
$this->paperHeight = ''; |
|
|
|
|
91
|
29 |
|
$this->margin = '1cm'; |
92
|
29 |
|
$this->format = 'A4'; |
93
|
29 |
|
$this->orientation = 'portrait'; |
94
|
29 |
|
$this->header = array(); |
95
|
29 |
|
$this->footer = array(); |
96
|
|
|
|
97
|
29 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get request type |
101
|
|
|
* |
102
|
|
|
* @access public |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
8 |
|
public function getType() |
106
|
|
|
{ |
107
|
8 |
|
if (!$this->type) { |
108
|
7 |
|
return RequestInterface::REQUEST_TYPE_PDF; |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
return $this->type; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set paper width. |
116
|
|
|
* |
117
|
|
|
* @access public |
118
|
|
|
* @param string $width |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
public function setPaperWidth($width) |
122
|
|
|
{ |
123
|
|
|
$this->paperWidth = $width; |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get paper width. |
128
|
|
|
* |
129
|
|
|
* @access public |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
7 |
|
public function getPaperWidth() |
133
|
|
|
{ |
134
|
7 |
|
return $this->paperWidth; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Set paper height. |
139
|
|
|
* |
140
|
|
|
* @access public |
141
|
|
|
* @param string $height |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
public function setPaperHeight($height) |
145
|
|
|
{ |
146
|
|
|
$this->paperHeight = $height; |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Get paper height. |
151
|
|
|
* |
152
|
|
|
* @access public |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
7 |
|
public function getPaperHeight() |
156
|
|
|
{ |
157
|
7 |
|
return $this->paperHeight; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Set paper size. |
162
|
|
|
* |
163
|
|
|
* @access public |
164
|
|
|
* @param string $width |
165
|
|
|
* @param string $height |
166
|
|
|
* @return void |
167
|
|
|
*/ |
168
|
3 |
|
public function setPaperSize($width, $height) |
169
|
|
|
{ |
170
|
3 |
|
$this->paperWidth = $width; |
|
|
|
|
171
|
3 |
|
$this->paperHeight = $height; |
|
|
|
|
172
|
3 |
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set format. |
176
|
|
|
* |
177
|
|
|
* @access public |
178
|
|
|
* @param string $format |
179
|
|
|
* @return void |
180
|
|
|
*/ |
181
|
4 |
|
public function setFormat($format) |
182
|
|
|
{ |
183
|
4 |
|
$this->format = $format; |
184
|
4 |
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get format. |
188
|
|
|
* |
189
|
|
|
* @access public |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
6 |
|
public function getFormat() |
193
|
|
|
{ |
194
|
6 |
|
return $this->format; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Set orientation. |
199
|
|
|
* |
200
|
|
|
* @access public |
201
|
|
|
* @param string $orientation |
202
|
|
|
* @return void |
203
|
|
|
*/ |
204
|
3 |
|
public function setOrientation($orientation) |
205
|
|
|
{ |
206
|
3 |
|
$this->orientation = $orientation; |
207
|
3 |
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Get orientation. |
211
|
|
|
* |
212
|
|
|
* @access public |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
6 |
|
public function getOrientation() |
216
|
|
|
{ |
217
|
6 |
|
return $this->orientation; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Set margin. |
222
|
|
|
* |
223
|
|
|
* @access public |
224
|
|
|
* @param string|array $margin |
225
|
|
|
* @return void |
226
|
|
|
*/ |
227
|
5 |
|
public function setMargin($margin) |
228
|
|
|
{ |
229
|
5 |
|
$this->margin = $margin; |
230
|
5 |
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Get margin. |
234
|
|
|
* |
235
|
|
|
* @access public |
236
|
|
|
* @return string|array |
237
|
|
|
*/ |
238
|
6 |
|
public function getMargin() |
239
|
|
|
{ |
240
|
6 |
|
return $this->margin; |
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Set repeating header. |
245
|
|
|
* |
246
|
|
|
* @access public |
247
|
|
|
* @param string $content |
248
|
|
|
* @param string $height (default: '1cm') |
249
|
|
|
* @return void |
250
|
|
|
*/ |
251
|
2 |
|
public function setRepeatingHeader($content, $height = '1cm') |
252
|
|
|
{ |
253
|
2 |
|
$this->header = array( |
254
|
2 |
|
'content' => $content, |
255
|
|
|
'height' => $height |
256
|
2 |
|
); |
257
|
2 |
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Get repeating header. |
261
|
|
|
* |
262
|
|
|
* @access public |
263
|
|
|
* @return array |
264
|
|
|
*/ |
265
|
6 |
|
public function getRepeatingHeader() |
266
|
|
|
{ |
267
|
6 |
|
return $this->header; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Set repeating footer. |
272
|
|
|
* |
273
|
|
|
* @access public |
274
|
|
|
* @param string $content |
275
|
|
|
* @param string $height (default: '1cm') |
276
|
|
|
* @return void |
277
|
|
|
*/ |
278
|
2 |
|
public function setRepeatingFooter($content, $height = '1cm') |
279
|
|
|
{ |
280
|
2 |
|
$this->footer = array( |
281
|
2 |
|
'content' => $content, |
282
|
|
|
'height' => $height |
283
|
2 |
|
); |
284
|
2 |
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Get repeating footer. |
288
|
|
|
* |
289
|
|
|
* @access public |
290
|
|
|
* @return array |
291
|
|
|
*/ |
292
|
6 |
|
public function getRepeatingFooter() |
293
|
|
|
{ |
294
|
6 |
|
return $this->footer; |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.