|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PdfMaker for Intraface |
|
4
|
|
|
* |
|
5
|
|
|
* @author Sune Jensen <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
class Intraface_Pdf extends Intraface_LegacyCpdf |
|
8
|
|
|
{ |
|
9
|
|
|
protected $value; |
|
10
|
|
|
protected $page; |
|
11
|
|
|
protected $page_height; |
|
12
|
|
|
protected $page_width; |
|
13
|
|
|
|
|
14
|
3 |
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
3 |
|
$this->page_width = 595; |
|
17
|
3 |
|
$this->page_height = 841; |
|
18
|
|
|
|
|
19
|
|
|
// Predefined values. |
|
20
|
3 |
|
$this->value['margin_top'] = 50; |
|
21
|
3 |
|
$this->value['margin_right'] = 42; |
|
22
|
3 |
|
$this->value['margin_left'] = 42; // From 0 to the edge in the left side |
|
23
|
3 |
|
$this->value['margin_bottom'] = 50; |
|
24
|
|
|
|
|
25
|
3 |
|
$this->value['header_height'] = 51; |
|
26
|
3 |
|
$this->value['header_margin_top'] = 20; |
|
27
|
3 |
|
$this->value['header_margin_bottom'] = 20; |
|
28
|
|
|
|
|
29
|
3 |
|
$this->value['font_size'] = 11; |
|
30
|
3 |
|
$this->value['font_padding_top'] = 1; |
|
31
|
3 |
|
$this->value['font_padding_bottom'] = 4; |
|
32
|
|
|
|
|
33
|
3 |
|
$this->page = 1; |
|
34
|
|
|
|
|
35
|
|
|
// Creates a new A4 document |
|
36
|
3 |
|
parent::__construct(array(0, 0, $this->page_width, $this->page_height)); |
|
37
|
|
|
|
|
38
|
|
|
// Rewrites the placement of Danish characters æ, ø, å, Æ, Ø, Å |
|
39
|
|
|
// After the Cpdf documentation |
|
40
|
|
|
// Table for the characters placements can be found here: http://www.fingertipsoft.com/3dkbd/ansitable.html |
|
41
|
|
|
// Table for their names is found here: http://www.gust.org.pl/fonty/qx-table2.htm |
|
42
|
|
|
// Notice that the placement of the characters are different in the two tables. Placement is correct in the first. |
|
43
|
|
|
|
|
44
|
3 |
|
$diff = array(230 => 'ae', |
|
45
|
3 |
|
198 => 'AE', |
|
46
|
3 |
|
248 => 'oslash', |
|
47
|
3 |
|
216 => 'Oslash', |
|
48
|
3 |
|
229 => 'aring', |
|
49
|
3 |
|
197 => 'Aring'); |
|
50
|
|
|
|
|
51
|
3 |
|
parent::selectFont('Helvetica.afm', array('differences' => $diff)); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
3 |
|
$this->calculateDynamicValues(); |
|
54
|
3 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Calculates all the dynamic values |
|
58
|
|
|
* Notice that X and Y are reset. |
|
59
|
|
|
* |
|
60
|
|
|
* @return void |
|
61
|
|
|
*/ |
|
62
|
3 |
|
private function calculateDynamicValues() |
|
63
|
|
|
{ |
|
64
|
|
|
// Sets values based on the predefined values. |
|
65
|
3 |
|
$this->value['right_margin_position'] = $this->page_width - $this->value['margin_right']; // content_width from 0 to right margen |
|
66
|
3 |
|
$this->value['top_margin_position'] = $this->page_height - $this->value['margin_top']; // content_height |
|
67
|
|
|
|
|
68
|
3 |
|
$this->value['content_width'] = $this->page_width - $this->value['margin_right'] - $this->value['margin_left']; // content_width fom 0 to right margen |
|
69
|
3 |
|
$this->value['content_height'] = $this->page_height - $this->value['margin_bottom'] - $this->value['margin_top']; // content_height |
|
70
|
|
|
|
|
71
|
3 |
|
$this->value['font_spacing'] = $this->value['font_size'] + $this->value['font_padding_top'] + $this->value['font_padding_bottom']; |
|
72
|
|
|
|
|
73
|
|
|
// X and Y are need to be reset, if the margins are changed. |
|
74
|
3 |
|
$this->setX(0); |
|
75
|
3 |
|
$this->setY(0); |
|
76
|
3 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Sets value |
|
80
|
|
|
* |
|
81
|
|
|
* @param integer $key The key to set |
|
82
|
|
|
* @param integer $value The value to put in the key |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function setValue($key, $value) |
|
87
|
|
|
{ |
|
88
|
1 |
|
$this->value[$key] = $value; |
|
89
|
|
|
// Every time we change a fixed value we need to update the dynamic values |
|
90
|
1 |
|
if (in_array($key, array('margin_right', 'margin_left', 'margin_top', 'margin_bottom', 'font_size', 'font_padding_top', 'font_padding_bottom'))) { |
|
91
|
1 |
|
$this->calculateDynamicValues(); |
|
92
|
1 |
|
} |
|
93
|
1 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Sets the x |
|
97
|
|
|
* |
|
98
|
|
|
* @param integer $value The x for the page |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
3 |
View Code Duplication |
public function setX($value) |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
3 |
|
if (is_int($value)) { |
|
105
|
3 |
|
$this->value['x'] = $this->get('margin_left') + $value; |
|
106
|
3 |
|
} elseif (is_string($value) && substr($value, 0, 1) == "+") { |
|
107
|
|
|
$this->value['x'] += intval(substr($value, 1)); |
|
108
|
|
|
} elseif (is_string($value) && substr($value, 0, 1) == "-") { |
|
109
|
|
|
$this->value['x'] -= intval(substr($value, 1)); |
|
110
|
|
|
} else { |
|
111
|
|
|
throw new Exception('Ugyldig værdi i setX: '.$value); |
|
112
|
|
|
} |
|
113
|
3 |
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Sets the y |
|
117
|
|
|
* |
|
118
|
|
|
* @param integer $value The y for the page |
|
119
|
|
|
* |
|
120
|
|
|
* @return void |
|
121
|
|
|
*/ |
|
122
|
3 |
View Code Duplication |
public function setY($value) |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
3 |
|
if (is_int($value)) { |
|
125
|
3 |
|
$this->value['y'] = $this->page_height - $this->get('margin_top') - $value; |
|
126
|
3 |
|
} elseif (is_string($value) && substr($value, 0, 1) == "+") { |
|
127
|
|
|
$this->value['y'] += intval(substr($value, 1)); |
|
128
|
|
|
} elseif (is_string($value) && substr($value, 0, 1) == "-") { |
|
129
|
|
|
$this->value['y'] -= intval(substr($value, 1)); |
|
130
|
|
|
} else { |
|
131
|
|
|
throw new Exception("Ugyldig værdi i setY: ".$value); |
|
132
|
|
|
} |
|
133
|
3 |
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Adds the header to the document |
|
137
|
|
|
* |
|
138
|
|
|
* @param string $headerImg The filepath for the header image |
|
139
|
|
|
* |
|
140
|
|
|
* @return void |
|
141
|
|
|
*/ |
|
142
|
|
|
public function addHeader($headerImg = '') |
|
143
|
|
|
{ |
|
144
|
|
|
if (!file_exists($headerImg)) { |
|
145
|
|
|
return false; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$header = parent::openObject(); |
|
|
|
|
|
|
149
|
|
|
$size = getImageSize($headerImg); // array(0 => width, 1 => height) |
|
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
$height = $this->get('header_height'); |
|
152
|
|
|
; |
|
153
|
|
|
$width = $size[0] * ($height/$size[1]); |
|
154
|
|
|
|
|
155
|
|
|
if ($width > $this->get('content_width')) { |
|
156
|
|
|
$width = $this->get('content_width'); |
|
157
|
|
|
$height = $size[1] * ($width/$size[0]); |
|
158
|
|
|
} |
|
159
|
|
|
parent::addJpegFromFile($headerImg, $this->get('right_margin_position') - $width, $this->page_height - $this->get('header_margin_top') - $height, $width, $height); // , ($this->value["page_width"] - $this->value["margin_left"])/10 |
|
|
|
|
|
|
160
|
|
|
parent::closeObject(); |
|
|
|
|
|
|
161
|
|
|
parent::addObject($header, "all"); |
|
|
|
|
|
|
162
|
|
|
$this->setValue('margin_top', $height + $this->get('header_margin_top') + $this->get('header_margin_bottom')); |
|
163
|
|
|
$this->setY(0); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* create a round rectangle |
|
168
|
|
|
* |
|
169
|
|
|
* @param integer $x The starting x point |
|
170
|
|
|
* @param integer $y The starting y point |
|
171
|
|
|
* @param integer $width The width of the rectangle |
|
172
|
|
|
* @param integer $height The height of the rectangle |
|
173
|
|
|
* @param integer $round How much to round the rectangle |
|
174
|
|
|
* |
|
175
|
|
|
* @return void |
|
176
|
|
|
*/ |
|
177
|
|
|
public function roundRectangle($x, $y, $width, $height, $round) |
|
178
|
|
|
{ |
|
179
|
|
|
parent::setLineStyle(1); |
|
|
|
|
|
|
180
|
|
|
parent::line($x, $y+$round, $x, $y+$height-$round); |
|
|
|
|
|
|
181
|
|
|
parent::line($x+$round, $y+$height, $x+$width-$round, $y+$height); |
|
|
|
|
|
|
182
|
|
|
parent::line($x+$width, $y+$height-$round, $x+$width, $y+$round-1); |
|
|
|
|
|
|
183
|
|
|
parent::line($x+$width-$round, $y, $x+$round, $y); |
|
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
parent::partEllipse($x+$round, $y+$round, 180, 270, $round); |
|
|
|
|
|
|
186
|
|
|
parent::partEllipse($x+$round, $y+$height-$round, 90, 180, $round); |
|
|
|
|
|
|
187
|
|
|
parent::partEllipse($x+$width-$round, $y+$height-$round, 0, 90, $round); |
|
|
|
|
|
|
188
|
|
|
parent::partEllipse($x+$width-$round, $y+$round, 270, 360, $round); |
|
|
|
|
|
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* write the document to a file |
|
193
|
|
|
* |
|
194
|
|
|
* @param string $data The data to write |
|
195
|
|
|
* |
|
196
|
|
|
* @return void |
|
197
|
|
|
*/ |
|
198
|
|
|
public function writeDocument($data, $filnavn) |
|
199
|
|
|
{ |
|
200
|
|
|
$file = fopen($filnavn, 'wb'); |
|
201
|
|
|
fwrite($file, $data); |
|
202
|
|
|
fclose($file); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
function addText($x, $y, $size, $text, $angle = 0, $wordSpaceAdjust = 0) |
|
206
|
|
|
{ |
|
207
|
|
|
$text = utf8_decode($text); |
|
208
|
|
|
parent::addText($x, $y, $size, $text, $angle = 0, $wordSpaceAdjust = 0); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Changes to next page |
|
213
|
|
|
* |
|
214
|
|
|
* @param boolean $sub_text What is the sub text |
|
215
|
|
|
* |
|
216
|
|
|
* @return integer the new y |
|
217
|
|
|
*/ |
|
218
|
|
|
public function nextPage($sub_text = false) |
|
219
|
|
|
{ |
|
220
|
|
|
if ($sub_text == true) { |
|
|
|
|
|
|
221
|
|
|
$this->addText($this->value['right_margin_position'] - $this->getTextWidth($this->value['font_size'], "<i>Fortsættes på næste side...</i>") - 30, $this->value["margin_bottom"] - $this->value['font_padding_top'] - $this->value['font_size'], $this->value['font_size'], "<i>Fortsættes på næste side...</i>"); |
|
222
|
|
|
} |
|
223
|
|
|
parent::newPage(); |
|
|
|
|
|
|
224
|
|
|
$this->setY(0); |
|
225
|
|
|
$this->page++; |
|
226
|
|
|
return $this->get('y'); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Get values |
|
231
|
|
|
* |
|
232
|
|
|
* @param string $key Which string to get |
|
233
|
|
|
* |
|
234
|
|
|
* @return mixed |
|
235
|
|
|
*/ |
|
236
|
3 |
|
public function get($key = '') |
|
237
|
|
|
{ |
|
238
|
3 |
|
if (!empty($key)) { |
|
239
|
3 |
|
return($this->value[$key]); |
|
240
|
|
|
} else { |
|
241
|
|
|
return $this->value; |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.