1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PDFtk wrapper |
4
|
|
|
* |
5
|
|
|
* @copyright 2014-2019 Institute of Legal Medicine, Medical University of Innsbruck |
6
|
|
|
* @author Andreas Erhard <[email protected]> |
7
|
|
|
* @license LGPL-3.0-only |
8
|
|
|
* @link http://www.gerichtsmedizin.at/ |
9
|
|
|
* |
10
|
|
|
* @package pdftk |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Gmi\Toolkit\Pdftk; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Represents a single PDF page. |
17
|
|
|
*/ |
18
|
|
|
class Page |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Page number in the PDF. |
22
|
|
|
* |
23
|
|
|
* @var int |
24
|
|
|
*/ |
25
|
|
|
private $pageNumber; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Height of the page in PostScript points (see pdftk dump_data). |
29
|
|
|
* |
30
|
|
|
* @var float |
31
|
|
|
*/ |
32
|
|
|
private $height; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Width of the page in PostScript points (see pdftk dump_data). |
36
|
|
|
* |
37
|
|
|
* @var float |
38
|
|
|
*/ |
39
|
|
|
private $width; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Rotation of the page in degrees (0 - no rotation). |
43
|
|
|
* |
44
|
|
|
* @var int |
45
|
|
|
*/ |
46
|
|
|
private $rotation; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Sets the page number. |
50
|
|
|
* |
51
|
|
|
* @param int $pageNumber |
52
|
|
|
* |
53
|
|
|
* @return self |
54
|
|
|
*/ |
55
|
5 |
|
public function setPageNumber($pageNumber) |
56
|
|
|
{ |
57
|
5 |
|
$this->pageNumber = $pageNumber; |
58
|
|
|
|
59
|
5 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the page number. |
64
|
|
|
* |
65
|
|
|
* @return int |
66
|
|
|
*/ |
67
|
2 |
|
public function getPageNumber() |
68
|
|
|
{ |
69
|
2 |
|
return $this->pageNumber; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Sets the page height. |
74
|
|
|
* |
75
|
|
|
* @param float $height |
76
|
|
|
* |
77
|
|
|
* @return self |
78
|
|
|
*/ |
79
|
5 |
|
public function setHeight($height) |
80
|
|
|
{ |
81
|
5 |
|
$this->height = $height; |
82
|
|
|
|
83
|
5 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the page height. |
88
|
|
|
* |
89
|
|
|
* @return float |
90
|
|
|
*/ |
91
|
1 |
|
public function getHeight() |
92
|
|
|
{ |
93
|
1 |
|
return $this->height; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the page height in millimeters, rounded to the millimeter. |
98
|
|
|
* |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
2 |
|
public function getHeightMm() |
102
|
|
|
{ |
103
|
2 |
|
return (int) round($this->convertPointToMm($this->height), 0); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Sets the page width. |
108
|
|
|
* |
109
|
|
|
* @param float $width |
110
|
|
|
* |
111
|
|
|
* @return self |
112
|
|
|
*/ |
113
|
5 |
|
public function setWidth($width) |
114
|
|
|
{ |
115
|
5 |
|
$this->width = $width; |
116
|
|
|
|
117
|
5 |
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the page width. |
122
|
|
|
* |
123
|
|
|
* @return float |
124
|
|
|
*/ |
125
|
1 |
|
public function getWidth() |
126
|
|
|
{ |
127
|
1 |
|
return $this->width; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Returns the page width in millimeters, rounded to the millimeter. |
132
|
|
|
* |
133
|
|
|
* @return int |
134
|
|
|
*/ |
135
|
3 |
|
public function getWidthMm() |
136
|
|
|
{ |
137
|
3 |
|
return (int) round($this->convertPointToMm($this->width), 0); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Sets the page rotation. |
142
|
|
|
* |
143
|
|
|
* @param int $rotation |
144
|
|
|
* |
145
|
|
|
* @return self |
146
|
|
|
*/ |
147
|
5 |
|
public function setRotation($rotation) |
148
|
|
|
{ |
149
|
5 |
|
$this->rotation = $rotation; |
150
|
|
|
|
151
|
5 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns the page rotation. |
156
|
|
|
* |
157
|
|
|
* @return int |
158
|
|
|
*/ |
159
|
3 |
|
public function getRotation() |
160
|
|
|
{ |
161
|
3 |
|
return $this->rotation; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Converts a measure of PostScript points to millimeters. |
166
|
|
|
* |
167
|
|
|
* @param float $point |
168
|
|
|
* |
169
|
|
|
* @return float |
170
|
|
|
*/ |
171
|
3 |
|
private function convertPointToMm($point) |
172
|
|
|
{ |
173
|
3 |
|
return $point / 72 * 25.4; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|