PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 2.4.5
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v2.4.5
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / mpdf / classes / mpdfform.php

mpdfform.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 2.4.5, at mpdf/classes/mpdfform.php

1,747 lines 67.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once __DIR__ . '/../MpdfException.php';
4
5 class mpdfform
6 {
7
8 var $mpdf = null;
9
10 var $forms;
11
12 var $formn;
13
14 // Active Forms
15 var $formSubmitNoValueFields;
16
17 var $formExportType;
18
19 var $formSelectDefaultOption;
20
21 var $formUseZapD;
22
23 // Form Styles
24 var $form_border_color;
25
26 var $form_background_color;
27
28 var $form_border_width;
29
30 var $form_border_style;
31
32 var $form_button_border_color;
33
34 var $form_button_background_color;
35
36 var $form_button_border_width;
37
38 var $form_button_border_style;
39
40 var $form_radio_color;
41
42 var $form_radio_background_color;
43
44 var $form_element_spacing;
45
46 // Active forms
47 var $formMethod;
48
49 var $formAction;
50
51 var $form_fonts;
52
53 var $form_radio_groups;
54
55 var $form_checkboxes;
56
57 var $pdf_acro_array;
58
59 var $pdf_array_co;
60
61 var $array_form_button_js;
62
63 var $array_form_choice_js;
64
65 var $array_form_text_js;
66
67 // Button Text
68 var $form_button_text;
69
70 var $form_button_text_over;
71
72 var $form_button_text_click;
73
74 var $form_button_icon;
75
76 // FORMS
77 var $textarea_lineheight;
78
79 public function __construct(mPDF $mpdf)
80 {
81 $this->mpdf = $mpdf;
82
83 // ACTIVE FORMS
84 $this->formExportType = 'xfdf'; // 'xfdf' or 'html'
85 $this->formSubmitNoValueFields = true; // Whether to include blank fields when submitting data
86 $this->formSelectDefaultOption = true; // for Select drop down box; if no option is explicitly maked as selected,
87 // this determines whether to select 1st option (as per browser)
88 // - affects whether "required" attribute is relevant
89 $this->formUseZapD = true; // Determine whether to use ZapfDingbat icons for radio/checkboxes
90 // FORM STYLES
91 // These can alternatively use a 4 number string to represent CMYK colours
92 $this->form_border_color = '0.6 0.6 0.72'; // RGB
93 $this->form_background_color = '0.975 0.975 0.975'; // RGB
94 $this->form_border_width = '1'; // 0 doesn't seem to work as it should
95 $this->form_border_style = 'S'; // B - Bevelled; D - Double
96 $this->form_button_border_color = '0.2 0.2 0.55';
97 $this->form_button_background_color = '0.941 0.941 0.941';
98 $this->form_button_border_width = '1';
99 $this->form_button_border_style = 'S';
100 $this->form_radio_color = '0.0 0.0 0.4'; // radio and checkbox
101 $this->form_radio_background_color = '0.9 0.9 0.9';
102
103 // FORMS
104 $this->textarea_lineheight = 1.25;
105
106 // FORM ELEMENT SPACING
107 $this->form_element_spacing['select']['outer']['h'] = 0.5; // Horizontal spacing around SELECT
108 $this->form_element_spacing['select']['outer']['v'] = 0.5; // Vertical spacing around SELECT
109 $this->form_element_spacing['select']['inner']['h'] = 0.7; // Horizontal padding around SELECT
110 $this->form_element_spacing['select']['inner']['v'] = 0.7; // Vertical padding around SELECT
111 $this->form_element_spacing['input']['outer']['h'] = 0.5;
112 $this->form_element_spacing['input']['outer']['v'] = 0.5;
113 $this->form_element_spacing['input']['inner']['h'] = 0.7;
114 $this->form_element_spacing['input']['inner']['v'] = 0.7;
115 $this->form_element_spacing['textarea']['outer']['h'] = 0.5;
116 $this->form_element_spacing['textarea']['outer']['v'] = 0.5;
117 $this->form_element_spacing['textarea']['inner']['h'] = 1;
118 $this->form_element_spacing['textarea']['inner']['v'] = 0.5;
119 $this->form_element_spacing['button']['outer']['h'] = 0.5;
120 $this->form_element_spacing['button']['outer']['v'] = 0.5;
121 $this->form_element_spacing['button']['inner']['h'] = 2;
122 $this->form_element_spacing['button']['inner']['v'] = 1;
123
124 // INITIALISE non-configurable
125 $this->formMethod = 'POST';
126 $this->formAction = '';
127 $this->form_fonts = array();
128 $this->form_radio_groups = array();
129 $this->form_checkboxes = false;
130 $this->forms = array();
131 $this->pdf_array_co = '';
132 }
133
134 function print_ob_text($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
135 {
136 // TEXT/PASSWORD INPUT
137 if ($this->mpdf->useActiveForms) {
138 // Flags: 1 - Readonly; 2 - Required; 3 - No export; 13 - textarea; 14 - Password
139 $flags = array();
140 if ((isset($objattr['disabled']) && $objattr['disabled']) || (isset($objattr['readonly']) && $objattr['readonly'])) {
141 $flags[] = 1;
142 } // readonly
143 if (isset($objattr['disabled']) && $objattr['disabled']) {
144 $flags[] = 3; // no export
145 $objattr['color'] = array(3, 128, 128, 128); // gray out disabled
146 }
147 if (isset($objattr['required']) && $objattr['required']) {
148 $flags[] = 2;
149 } // required
150 if (!isset($objattr['spellcheck']) || !$objattr['spellcheck']) {
151 $flags[] = 23;
152 } // DoNotSpellCheck
153 if (isset($objattr['subtype']) && $objattr['subtype'] == 'PASSWORD') {
154 $flags[] = 14;
155 $val = $objattr['value'];
156 }
157 if (isset($objattr['color'])) {
158 $this->mpdf->SetTColor($objattr['color']);
159 } else {
160 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
161 }
162 $fieldalign = $rtlalign;
163 if (isset($objattr['text_align']) && $objattr['text_align']) {
164 $fieldalign = $objattr['text_align'];
165 } else {
166 $val = $objattr['text'];
167 }
168 // mPDF 5.3.25
169 $js = array();
170 if (isset($objattr['onCalculate']) && $objattr['onCalculate']) {
171 $js[] = array('C', $objattr['onCalculate']);
172 }
173 if (isset($objattr['onValidate']) && $objattr['onValidate']) {
174 $js[] = array('V', $objattr['onValidate']);
175 }
176 if (isset($objattr['onFormat']) && $objattr['onFormat']) {
177 $js[] = array('F', $objattr['onFormat']);
178 }
179 if (isset($objattr['onKeystroke']) && $objattr['onKeystroke']) {
180 $js[] = array('K', $objattr['onKeystroke']);
181 }
182 $this->SetFormText($w, $h, $objattr['fieldname'], $val, $val, $objattr['title'], $flags, $fieldalign, false, (isset($objattr['maxlength']) ? $objattr['maxlength'] : false), $js, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false));
183 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
184 } else {
185 $w -= $this->form_element_spacing['input']['outer']['h'] * 2 / $k;
186 $h -= $this->form_element_spacing['input']['outer']['v'] * 2 / $k;
187 $this->mpdf->x += $this->form_element_spacing['input']['outer']['h'] / $k;
188 $this->mpdf->y += $this->form_element_spacing['input']['outer']['v'] / $k;
189 // Chop texto to max length $w-inner-padding
190 while ($this->mpdf->GetStringWidth($texto) > $w - ($this->form_element_spacing['input']['inner']['h'] * 2)) {
191 $texto = mb_substr($texto, 0, mb_strlen($texto, $this->mpdf->mb_enc) - 1, $this->mpdf->mb_enc);
192 }
193
194 // DIRECTIONALITY
195 if (preg_match("/([" . $this->mpdf->pregRTLchars . "])/u", $texto)) {
196 $this->mpdf->biDirectional = true;
197 } // *RTL*
198 // Use OTL OpenType Table Layout - GSUB & GPOS
199 if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
200 $texto = $this->mpdf->otl->applyOTL($texto, $this->mpdf->CurrentFont['useOTL']);
201 $OTLdata = $this->mpdf->otl->OTLdata;
202 }
203
204 $this->mpdf->magic_reverse_dir($texto, $this->mpdf->directionality, $OTLdata);
205
206 $this->mpdf->SetLineWidth(0.2 / $k);
207 if (isset($objattr['disabled']) && $objattr['disabled']) {
208 $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
209 $this->mpdf->SetTColor($this->mpdf->ConvertColor(127));
210 } else if (isset($objattr['readonly']) && $objattr['readonly']) {
211 $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
212 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
213 } else {
214 $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
215 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
216 }
217 $this->mpdf->Cell($w, $h, $texto, 1, 0, $rtlalign, 1, '', 0, $this->form_element_spacing['input']['inner']['h'] / $k, $this->form_element_spacing['input']['inner']['h'] / $k, 'M', 0, false, $OTLdata);
218 $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
219 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
220 }
221 }
222
223 function print_ob_textarea($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
224 {
225 // TEXTAREA
226 if ($this->mpdf->useActiveForms) {
227 // Flags: 1 - Readonly; 2 - Required; 3 - No export; 13 - textarea; 14 - Password
228 $flags = array();
229 $flags = array(13); // textarea
230 if ((isset($objattr['disabled']) && $objattr['disabled']) || (isset($objattr['readonly']) && $objattr['readonly'])) {
231 $flags[] = 1;
232 } // readonly
233 if (isset($objattr['disabled']) && $objattr['disabled']) {
234 $flags[] = 3; // no export
235 $objattr['color'] = array(3, 128, 128, 128); // gray out disabled
236 }
237 if (isset($objattr['required']) && $objattr['required']) {
238 $flags[] = 2;
239 } // required
240 if (!isset($objattr['spellcheck']) || !$objattr['spellcheck']) {
241 $flags[] = 23;
242 } // DoNotSpellCheck
243 if (isset($objattr['donotscroll']) && $objattr['donotscroll']) {
244 $flags[] = 24;
245 } // DoNotScroll
246 if (isset($objattr['color'])) {
247 $this->mpdf->SetTColor($objattr['color']);
248 } else {
249 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
250 }
251 $fieldalign = $rtlalign;
252 if ($texto == ' ') {
253 $texto = '';
254 } // mPDF 5.3.24
255 if (isset($objattr['text_align']) && $objattr['text_align']) {
256 $fieldalign = $objattr['text_align'];
257 }
258 // mPDF 5.3.25
259 $js = array();
260 if (isset($objattr['onCalculate']) && $objattr['onCalculate']) {
261 $js[] = array('C', $objattr['onCalculate']);
262 }
263 if (isset($objattr['onValidate']) && $objattr['onValidate']) {
264 $js[] = array('V', $objattr['onValidate']);
265 }
266 if (isset($objattr['onFormat']) && $objattr['onFormat']) {
267 $js[] = array('F', $objattr['onFormat']);
268 }
269 if (isset($objattr['onKeystroke']) && $objattr['onKeystroke']) {
270 $js[] = array('K', $objattr['onKeystroke']);
271 }
272 $this->SetFormText($w, $h, $objattr['fieldname'], $texto, $texto, (isset($objattr['title']) ? $objattr['title'] : ''), $flags, $fieldalign, false, -1, $js, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false));
273 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
274 } else {
275 $w -= $this->form_element_spacing['textarea']['outer']['h'] * 2 / $k;
276 $h -= $this->form_element_spacing['textarea']['outer']['v'] * 2 / $k;
277 $this->mpdf->x += $this->form_element_spacing['textarea']['outer']['h'] / $k;
278 $this->mpdf->y += $this->form_element_spacing['textarea']['outer']['v'] / $k;
279 $this->mpdf->SetLineWidth(0.2 / $k);
280 if (isset($objattr['disabled']) && $objattr['disabled']) {
281 $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
282 $this->mpdf->SetTColor($this->mpdf->ConvertColor(127));
283 } else if (isset($objattr['readonly']) && $objattr['readonly']) {
284 $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
285 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
286 } else {
287 $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
288 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
289 }
290 $this->mpdf->Rect($this->mpdf->x, $this->mpdf->y, $w, $h, 'DF');
291 $ClipPath = sprintf('q %.3F %.3F %.3F %.3F re W n ', $this->mpdf->x * _MPDFK, ($this->mpdf->h - $this->mpdf->y) * _MPDFK, $w * _MPDFK, -$h * _MPDFK);
292 $this->mpdf->_out($ClipPath);
293
294 $w -= $this->form_element_spacing['textarea']['inner']['h'] * 2 / $k;
295 $this->mpdf->x += $this->form_element_spacing['textarea']['inner']['h'] / $k;
296 $this->mpdf->y += $this->form_element_spacing['textarea']['inner']['v'] / $k;
297
298 if ($texto != '')
299 $this->mpdf->MultiCell($w, $this->mpdf->FontSize * $this->textarea_lineheight, $texto, 0, '', 0, '', $blockdir, true, $objattr['OTLdata'], $objattr['rows']);
300 $this->mpdf->_out('Q');
301 $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
302 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
303 }
304 }
305
306 function print_ob_select($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
307 {
308 // SELECT
309 if ($this->mpdf->useActiveForms) {
310 // Flags: 1 - Readonly; 2 - Required; 3 - No export; 19 - edit (only if combo)
311 $flags = array();
312 if (isset($objattr['disabled']) && $objattr['disabled']) {
313 $flags[] = 1; // readonly
314 $flags[] = 3; // no export
315 $objattr['color'] = array(3, 128, 128, 128); // gray out disabled
316 }
317 if (isset($objattr['required']) && $objattr['required']) {
318 $flags[] = 2;
319 } // required
320 if (isset($objattr['multiple']) && $objattr['multiple'] && isset($objattr['size']) && $objattr['size'] > 1) {
321 $flags[] = 22;
322 } //flag 22 = multiselect (listbox)
323 if (isset($objattr['size']) && $objattr['size'] < 2) {
324 $flags[] = 18; //flag 18 = combobox (else a listbox)
325 if (isset($objattr['editable']) && $objattr['editable']) {
326 $flags[] = 19;
327 } // editable
328 }
329 // only allow spellcheck if combo and editable
330 if ((!isset($objattr['spellcheck']) || !$objattr['spellcheck']) || (isset($objattr['size']) && $objattr['size'] > 1) || (!isset($objattr['editable']) || !$objattr['editable'])) {
331 $flags[] = 23;
332 } // DoNotSpellCheck
333 if (isset($objattr['subtype']) && $objattr['subtype'] == 'PASSWORD') {
334 $flags[] = 14;
335 }
336 if (isset($objattr['onChange']) && $objattr['onChange']) {
337 $js = $objattr['onChange'];
338 } else {
339 $js = '';
340 } // mPDF 5.3.37
341 $data = array('VAL' => array(), 'OPT' => array(), 'SEL' => array(),);
342 if (isset($objattr['items'])) {
343 for ($i = 0; $i < count($objattr['items']); $i++) {
344 $item = $objattr['items'][$i];
345 $data['VAL'][] = (isset($item['exportValue']) ? $item['exportValue'] : '');
346 $data['OPT'][] = (isset($item['content']) ? $item['content'] : '');
347 if (isset($item['selected']) && $item['selected']) {
348 $data['SEL'][] = $i;
349 }
350 }
351 }
352 if (count($data['SEL']) == 0 && $this->formSelectDefaultOption) {
353 $data['SEL'][] = 0;
354 }
355 if (isset($objattr['color'])) {
356 $this->mpdf->SetTColor($objattr['color']);
357 } else {
358 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
359 }
360 $this->SetFormChoice($w, $h, $objattr['fieldname'], $flags, $data, $rtlalign, $js);
361 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
362 } else {
363 $this->mpdf->SetLineWidth(0.2 / $k);
364 if (isset($objattr['disabled']) && $objattr['disabled']) {
365 $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
366 $this->mpdf->SetTColor($this->mpdf->ConvertColor(127));
367 } else {
368 $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
369 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
370 }
371 $w -= $this->form_element_spacing['select']['outer']['h'] * 2 / $k;
372 $h -= $this->form_element_spacing['select']['outer']['v'] * 2 / $k;
373 $this->mpdf->x += $this->form_element_spacing['select']['outer']['h'] / $k;
374 $this->mpdf->y += $this->form_element_spacing['select']['outer']['v'] / $k;
375
376 // DIRECTIONALITY
377 if (preg_match("/([" . $this->mpdf->pregRTLchars . "])/u", $texto)) {
378 $this->mpdf->biDirectional = true;
379 } // *RTL*
380
381 $this->mpdf->magic_reverse_dir($texto, $this->mpdf->directionality, $objattr['OTLdata']);
382
383 $this->mpdf->Cell($w - ($this->mpdf->FontSize * 1.4), $h, $texto, 1, 0, $rtlalign, 1, '', 0, $this->form_element_spacing['select']['inner']['h'] / $k, $this->form_element_spacing['select']['inner']['h'] / $k, 'M', 0, false, $objattr['OTLdata']);
384 $this->mpdf->SetFColor($this->mpdf->ConvertColor(190));
385 $save_font = $this->mpdf->FontFamily;
386 $save_currentfont = $this->mpdf->currentfontfamily;
387 if ($this->mpdf->PDFA || $this->mpdf->PDFX) {
388 if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
389 $this->mpdf->PDFAXwarnings[] = "Core Adobe font Zapfdingbats cannot be embedded in mPDF - used in Form element: Select - which is required for PDFA1-b or PDFX/1-a. (Different character/font will be substituted.)";
390 }
391 $this->mpdf->SetFont('sans');
392 if ($this->mpdf->_charDefined($this->mpdf->CurrentFont['cw'], 9660)) {
393 $down = "\xe2\x96\xbc";
394 } else {
395 $down = '=';
396 }
397 $this->mpdf->Cell(($this->mpdf->FontSize * 1.4), $h, $down, 1, 0, 'C', 1, '', 0, 0, 0, 'M');
398 } else {
399 $this->mpdf->SetFont('czapfdingbats', '', 0);
400 $this->mpdf->Cell(($this->mpdf->FontSize * 1.4), $h, chr(116), 1, 0, 'C', 1, '', 0, 0, 0, 'M');
401 }
402 $this->mpdf->SetFont($save_font, '', 0);
403 $this->mpdf->currentfontfamily = $save_currentfont;
404 $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
405 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
406 }
407 }
408
409 function print_ob_imageinput($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
410 {
411 // INPUT/BUTTON as IMAGE
412 if ($this->mpdf->useActiveForms) {
413 // Flags: 1 - Readonly; 3 - No export;
414 $flags = array();
415 if (isset($objattr['disabled']) && $objattr['disabled']) {
416 $flags[] = 1; // readonly
417 $flags[] = 3; // no export
418 }
419 if (isset($objattr['onClick']) && $objattr['onClick']) {
420 $js = $objattr['onClick'];
421 } else {
422 $js = '';
423 }
424 $this->SetJSButton($w, $h, $objattr['fieldname'], (isset($objattr['value']) ? $objattr['value'] : ''), $js, $objattr['ID'], $objattr['title'], $flags, (isset($objattr['Indexed']) ? $objattr['Indexed'] : false));
425 } else {
426 $this->mpdf->y = $objattr['INNER-Y'];
427 $this->mpdf->_out(sprintf("q %.3F 0 0 %.3F %.3F %.3F cm /I%d Do Q", $objattr['INNER-WIDTH'] * _MPDFK, $objattr['INNER-HEIGHT'] * _MPDFK, $objattr['INNER-X'] * _MPDFK, ($this->mpdf->h - ($objattr['INNER-Y'] + $objattr['INNER-HEIGHT'] )) * _MPDFK, $objattr['ID']));
428 if (isset($objattr['BORDER-WIDTH']) && $objattr['BORDER-WIDTH']) {
429 $this->mpdf->PaintImgBorder($objattr, $is_table);
430 }
431 }
432 }
433
434 function print_ob_button($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir)
435 {
436 // BUTTON
437 if ($this->mpdf->useActiveForms) {
438 // Flags: 1 - Readonly; 3 - No export;
439 $flags = array();
440 if (isset($objattr['disabled']) && $objattr['disabled']) {
441 $flags[] = 1; // readonly
442 $flags[] = 3; // no export
443 $objattr['color'] = array(3, 128, 128, 128);
444 }
445 if (isset($objattr['color'])) {
446 $this->mpdf->SetTColor($objattr['color']);
447 } else {
448 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
449 }
450 if (isset($objattr['subtype']) && $objattr['subtype'] == 'RESET') {
451 $this->SetFormButtonText($objattr['value']);
452 $this->SetFormReset($w, $h, $objattr['fieldname'], $objattr['value'], $objattr['title'], $flags, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false), (isset($objattr['noprint']) ? $objattr['noprint'] : false));
453 } else if (isset($objattr['subtype']) && $objattr['subtype'] == 'SUBMIT') {
454 $url = $this->formAction;
455 $type = $this->formExportType;
456 $method = $this->formMethod;
457 $this->SetFormButtonText($objattr['value']);
458 $this->SetFormSubmit($w, $h, $objattr['fieldname'], $objattr['value'], $url, $objattr['title'], $type, $method, $flags, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false), (isset($objattr['noprint']) ? $objattr['noprint'] : false));
459 } else if (isset($objattr['subtype']) && $objattr['subtype'] == 'BUTTON') {
460 $this->SetFormButtonText($objattr['value']);
461 if (isset($objattr['onClick']) && $objattr['onClick']) {
462 $js = $objattr['onClick'];
463 } else {
464 $js = '';
465 }
466 $this->SetJSButton($w, $h, $objattr['fieldname'], $objattr['value'], $js, 0, $objattr['title'], $flags, false, (isset($objattr['background-col']) ? $objattr['background-col'] : false), (isset($objattr['border-col']) ? $objattr['border-col'] : false), (isset($objattr['noprint']) ? $objattr['noprint'] : false));
467 }
468 $this->mpdf->SetTColor($this->mpdf->ConvertColor(0));
469 } else {
470 $this->mpdf->SetLineWidth(0.2 / $k);
471 $this->mpdf->SetFColor($this->mpdf->ConvertColor(190));
472 $w -= $this->form_element_spacing['button']['outer']['h'] * 2 / $k;
473 $h -= $this->form_element_spacing['button']['outer']['v'] * 2 / $k;
474 $this->mpdf->x += $this->form_element_spacing['button']['outer']['h'] / $k;
475 $this->mpdf->y += $this->form_element_spacing['button']['outer']['v'] / $k;
476 $this->mpdf->RoundedRect($this->mpdf->x, $this->mpdf->y, $w, $h, 0.5 / $k, 'DF');
477 $w -= $this->form_element_spacing['button']['inner']['h'] * 2 / $k;
478 $h -= $this->form_element_spacing['button']['inner']['v'] * 2 / $k;
479 $this->mpdf->x += $this->form_element_spacing['button']['inner']['h'] / $k;
480 $this->mpdf->y += $this->form_element_spacing['button']['inner']['v'] / $k;
481
482 // DIRECTIONALITY
483 if (preg_match("/([" . $this->mpdf->pregRTLchars . "])/u", $texto)) {
484 $this->mpdf->biDirectional = true;
485 } // *RTL*
486 // Use OTL OpenType Table Layout - GSUB & GPOS
487 if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
488 $texto = $this->mpdf->otl->applyOTL($texto, $this->mpdf->CurrentFont['useOTL']);
489 $OTLdata = $this->mpdf->otl->OTLdata;
490 }
491
492 $this->mpdf->magic_reverse_dir($texto, $this->mpdf->directionality, $OTLdata);
493
494 $this->mpdf->Cell($w, $h, $texto, '', 0, 'C', 0, '', 0, 0, 0, 'M', 0, false, $OTLdata);
495 $this->mpdf->SetFColor($this->mpdf->ConvertColor(0));
496 }
497 }
498
499 function print_ob_checkbox($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir, $x, $y)
500 {
501 // CHECKBOX
502 if ($this->mpdf->useActiveForms) {
503 // Flags: 1 - Readonly; 2 - Required; 3 - No export;
504 $flags = array();
505 if (isset($objattr['disabled']) && $objattr['disabled']) {
506 $flags[] = 1; // readonly
507 $flags[] = 3; // no export
508 }
509 $checked = false;
510 if (isset($objattr['checked']) && $objattr['checked']) {
511 $checked = true;
512 }
513 if ($this->formUseZapD) {
514 $save_font = $this->mpdf->FontFamily;
515 $save_currentfont = $this->mpdf->currentfontfamily;
516 $this->mpdf->SetFont('czapfdingbats', '', 0);
517 }
518 $this->SetCheckBox($w, $h, $objattr['fieldname'], $objattr['value'], $objattr['title'], $checked, $flags, (isset($objattr['disabled']) ? $objattr['disabled'] : false));
519 if ($this->formUseZapD) {
520 $this->mpdf->SetFont($save_font, '', 0);
521 $this->mpdf->currentfontfamily = $save_currentfont;
522 }
523 } else {
524 $iw = $w * 0.7;
525 $ih = $h * 0.7;
526 $lx = $x + (($w - $iw) / 2);
527 $ty = $y + (($h - $ih) / 2);
528 $rx = $lx + $iw;
529 $by = $ty + $ih;
530 $this->mpdf->SetLineWidth(0.2 / $k);
531 if (isset($objattr['disabled']) && $objattr['disabled']) {
532 $this->mpdf->SetFColor($this->mpdf->ConvertColor(225));
533 $this->mpdf->SetDColor($this->mpdf->ConvertColor(127));
534 } else {
535 $this->mpdf->SetFColor($this->mpdf->ConvertColor(250));
536 $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
537 }
538 $this->mpdf->Rect($lx, $ty, $iw, $ih, 'DF');
539 if (isset($objattr['checked']) && $objattr['checked']) {
540 //Round join and cap
541 $this->mpdf->SetLineCap(1);
542 $this->mpdf->Line($lx, $ty, $rx, $by);
543 $this->mpdf->Line($lx, $by, $rx, $ty);
544 //Set line cap style back to square
545 $this->mpdf->SetLineCap(2);
546 }
547 $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
548 $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
549 }
550 }
551
552 function print_ob_radio($objattr, $w, $h, $texto, $rtlalign, $k, $blockdir, $x, $y)
553 {
554 // RADIO
555 if ($this->mpdf->useActiveForms) {
556 // Flags: 1 - Readonly; 2 - Required; 3 - No export;
557 $flags = array();
558 if (isset($objattr['disabled']) && $objattr['disabled']) {
559 $flags[] = 1; // readonly
560 $flags[] = 3; // no export
561 }
562 $checked = false;
563 if (isset($objattr['checked']) && $objattr['checked']) {
564 $checked = true;
565 }
566 if ($this->formUseZapD) {
567 $save_font = $this->mpdf->FontFamily;
568 $save_currentfont = $this->mpdf->currentfontfamily;
569 $this->mpdf->SetFont('czapfdingbats', '', 0);
570 }
571 $this->SetRadio($w, $h, $objattr['fieldname'], $objattr['value'], (isset($objattr['title']) ? $objattr['title'] : ''), $checked, $flags, (isset($objattr['disabled']) ? $objattr['disabled'] : false));
572 if ($this->formUseZapD) {
573 $this->mpdf->SetFont($save_font, '', 0);
574 $this->mpdf->currentfontfamily = $save_currentfont;
575 }
576 } else {
577 $this->mpdf->SetLineWidth(0.2 / $k);
578 $radius = $this->mpdf->FontSize * 0.35;
579 $cx = $x + ($w / 2);
580 $cy = $y + ($h / 2);
581 if (isset($objattr['disabled']) && $objattr['disabled']) {
582 $this->mpdf->SetFColor($this->mpdf->ConvertColor(127));
583 $this->mpdf->SetDColor($this->mpdf->ConvertColor(127));
584 } else {
585 $this->mpdf->SetFColor($this->mpdf->ConvertColor(0));
586 $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
587 }
588 $this->mpdf->Circle($cx, $cy, $radius, 'D');
589 if (isset($objattr['checked']) && $objattr['checked']) {
590 $this->mpdf->Circle($cx, $cy, $radius * 0.4, 'DF');
591 }
592 $this->mpdf->SetFColor($this->mpdf->ConvertColor(255));
593 $this->mpdf->SetDColor($this->mpdf->ConvertColor(0));
594 }
595 }
596
597 // In _putpages
598 function countPageForms($n, &$totaladdnum)
599 {
600 foreach ($this->forms as $form) {
601 if ($form['page'] == $n) {
602 $totaladdnum++;
603 if ($form['typ'] == 'Tx') {
604 if (isset($this->array_form_text_js[$form['T']])) {
605 if (isset($this->array_form_text_js[$form['T']]['F'])) {
606 $totaladdnum++;
607 }
608 if (isset($this->array_form_text_js[$form['T']]['K'])) {
609 $totaladdnum++;
610 }
611 if (isset($this->array_form_text_js[$form['T']]['V'])) {
612 $totaladdnum++;
613 }
614 if (isset($this->array_form_text_js[$form['T']]['C'])) {
615 $totaladdnum++;
616 }
617 }
618 }
619 if ($form['typ'] == 'Bt') {
620 if (isset($this->array_form_button_js[$form['T']])) {
621 $totaladdnum++;
622 }
623 if (isset($this->form_button_icon[$form['T']])) {
624 $totaladdnum++;
625 if ($this->form_button_icon[$form['T']]['Indexed']) {
626 $totaladdnum++;
627 }
628 }
629 if ($form['subtype'] == 'radio') {
630 $totaladdnum+=2;
631 } else if ($form['subtype'] == 'checkbox' && $this->formUseZapD) {
632 $totaladdnum++;
633 } else if ($form['subtype'] == 'checkbox' && !$this->formUseZapD) {
634 $totaladdnum+=2;
635 }
636 }
637 if ($form['typ'] == 'Ch') {
638 if (isset($this->array_form_choice_js[$form['T']])) {
639 $totaladdnum++;
640 }
641 }
642 }
643 }
644 }
645
646 // In _putpages
647 function addFormIds($n, &$s, &$annotid)
648 {
649 foreach ($this->forms as $form) {
650 if ($form['page'] == $n) {
651 $s .= ($annotid) . ' 0 R ';
652 $annotid++;
653 if ($form['typ'] == 'Tx') {
654 if (isset($this->array_form_text_js[$form['T']])) {
655 if (isset($this->array_form_text_js[$form['T']]['F'])) {
656 $annotid++;
657 }
658 if (isset($this->array_form_text_js[$form['T']]['K'])) {
659 $annotid++;
660 }
661 if (isset($this->array_form_text_js[$form['T']]['V'])) {
662 $annotid++;
663 }
664 if (isset($this->array_form_text_js[$form['T']]['C'])) {
665 $annotid++;
666 }
667 }
668 }
669 if ($form['typ'] == 'Bt') {
670 if (isset($this->array_form_button_js[$form['T']])) {
671 $annotid++;
672 }
673 if (isset($this->form_button_icon[$form['T']])) {
674 $annotid++;
675 if ($this->form_button_icon[$form['T']]['Indexed']) {
676 $annotid++;
677 }
678 }
679 if ($form['subtype'] == 'radio') {
680 $annotid+=2;
681 } else if ($form['subtype'] == 'checkbox' && $this->formUseZapD) {
682 $annotid++;
683 } else if ($form['subtype'] == 'checkbox' && !$this->formUseZapD) {
684 $annotid+=2;
685 }
686 }
687 if ($form['typ'] == 'Ch') {
688 if (isset($this->array_form_choice_js[$form['T']])) {
689 $annotid++;
690 }
691 }
692 }
693 }
694 }
695
696 // In _putannots
697 function _putFormItems($n, $hPt)
698 {
699 foreach ($this->forms as $val) {
700 if ($val['page'] == $n) {
701 if ($val['typ'] == 'Tx')
702 $this->_putform_tx($val, $hPt);
703 if ($val['typ'] == 'Ch')
704 $this->_putform_ch($val, $hPt);
705 if ($val['typ'] == 'Bt')
706 $this->_putform_bt($val, $hPt);
707 }
708 }
709 }
710
711 // In _putannots
712 function _putRadioItems($n)
713 {
714 // Output Radio Groups
715 $key = 1;
716 foreach ($this->form_radio_groups AS $name => $frg) {
717 $this->mpdf->_newobj();
718 $this->pdf_acro_array .= $this->mpdf->n . ' 0 R ';
719 $this->mpdf->_out('<<');
720 $this->mpdf->_out('/Type /Annot ');
721 $this->mpdf->_out('/Subtype /Widget');
722 $this->mpdf->_out('/NM ' . $this->mpdf->_textstring(sprintf('%04u-%04u', $n, (3000 + $key++))));
723 $this->mpdf->_out('/M ' . $this->mpdf->_textstring('D:' . date('YmdHis')));
724 $this->mpdf->_out('/Rect [0 0 0 0] ');
725 $this->mpdf->_out('/FT /Btn ');
726 if (isset($frg['disabled']) && $frg['disabled']) {
727 $flags = array(1, 3, 15, 16);
728 } // NoExport and readonly
729 else {
730 $flags = array(15, 16);
731 } // Flags for Radiobutton, and NoToggleToOff
732 $this->mpdf->_out('/Ff ' . $this->_setflag($flags));
733 $kstr = '';
734 $optstr = '';
735 foreach ($frg['kids'] AS $kid) {
736 $kstr .= $this->forms[$kid['n']]['obj'] . ' 0 R ';
737 // $optstr .= ' '.$this->mpdf->_textstring($kid['OPT']).' ';
738 }
739 $this->mpdf->_out('/Kids [ ' . $kstr . ' ] '); // 11 0 R 12 0 R etc.
740 // $this->mpdf->_out('/Opt [ '.$optstr.' ] ');
741 //V entry holds index corresponding to the appearance state of
742 //whichever child field is currently in the on state = or Off
743 if (isset($frg['on'])) {
744 $state = $frg['on'];
745 } else {
746 $state = 'Off';
747 }
748 $this->mpdf->_out('/V /' . $state . ' ');
749 $this->mpdf->_out('/DV /' . $state . ' ');
750 $this->mpdf->_out('/T ' . $this->mpdf->_textstring($name) . ' ');
751 $this->mpdf->_out('>>');
752 $this->mpdf->_out('endobj');
753 }
754 }
755
756 function _putFormsCatalog()
757 {
758 if (isset($this->pdf_acro_array)) {
759 $this->mpdf->_out('/AcroForm << /DA (/F1 0 Tf 0 g )');
760 $this->mpdf->_out('/Q 0');
761 $this->mpdf->_out('/Fields [' . $this->pdf_acro_array . ']');
762 $f = '';
763 foreach ($this->form_fonts AS $fn) {
764 if (is_array($this->mpdf->fonts[$fn]['n'])) {
765 $this->mpdf->Error("Cannot use fonts with SMP or SIP characters for interactive Form elements");
766 }
767 $f .= '/F' . $this->mpdf->fonts[$fn]['i'] . ' ' . $this->mpdf->fonts[$fn]['n'] . ' 0 R ';
768 }
769 $this->mpdf->_out('/DR << /Font << ' . $f . ' >> >>');
770 // CO Calculation Order
771 if ($this->pdf_array_co) {
772 $this->mpdf->_out('/CO [' . $this->pdf_array_co . ']');
773 }
774 $this->mpdf->_out('/NeedAppearances true');
775 $this->mpdf->_out('>>');
776 }
777 }
778
779 function SetFormButtonJS($name, $js)
780 {
781 $js = str_replace("\t", ' ', trim($js));
782 if (isset($name) && isset($js)) {
783 $this->array_form_button_js[$this->mpdf->_escape($name)] = array(
784 'js' => $js
785 );
786 }
787 }
788
789 function SetFormChoiceJS($name, $js)
790 {
791 $js = str_replace("\t", ' ', trim($js));
792 if (isset($name) && isset($js)) {
793 $this->array_form_choice_js[$this->mpdf->_escape($name)] = array(
794 'js' => $js
795 );
796 }
797 }
798
799 function SetFormTextJS($name, $js)
800 {
801 for ($i = 0; $i < count($js); $i++) {
802 $j = str_replace("\t", ' ', trim($js[$i][1]));
803 $format = $js[$i][0];
804 if ($name) {
805 $this->array_form_text_js[$this->mpdf->_escape($name)][$format] = array('js' => $j);
806 }
807 }
808 }
809
810 function Win1252ToPDFDocEncoding($txt)
811 {
812 $Win1252ToPDFDocEncoding = array(
813 chr(0200) => chr(0240), chr(0214) => chr(0226), chr(0212) => chr(0227), chr(0237) => chr(0230),
814 chr(0225) => chr(0200), chr(0210) => chr(0032), chr(0206) => chr(0201), chr(0207) => chr(0202),
815 chr(0205) => chr(0203), chr(0227) => chr(0204), chr(0226) => chr(0205), chr(0203) => chr(0206),
816 chr(0213) => chr(0210), chr(0233) => chr(0211), chr(0211) => chr(0213), chr(0204) => chr(0214),
817 chr(0223) => chr(0215), chr(0224) => chr(0216), chr(0221) => chr(0217), chr(0222) => chr(0220),
818 chr(0202) => chr(0221), chr(0232) => chr(0235), chr(0230) => chr(0037), chr(0231) => chr(0222),
819 chr(0216) => chr(0231), chr(0240) => chr(0040)
820 ); // mPDF 5.3.46
821 return strtr($txt, $Win1252ToPDFDocEncoding);
822 }
823
824 function SetFormText($w, $h, $name, $value = '', $default = '', $title = '', $flags = array(), $align = 'L', $hidden = false, $maxlen = -1, $js = '', $background_col = false, $border_col = false)
825 {
826 // Flags: 1 - Readonly; 2 - Required; 3 - No export; 13 - textarea; 14 - Password
827 $this->formn++;
828 if ($align == 'C') {
829 $align = '1';
830 } else if ($align == 'R') {
831 $align = '2';
832 } else {
833 $align = '0';
834 }
835 if ($maxlen < 1) {
836 $maxlen = false;
837 }
838 if (!preg_match('/^[a-zA-Z0-9_:\-]+$/', $name)) {
839 $this->mpdf->Error("Field [" . $name . "] must have a name attribute, which can only contain letters, numbers, colon(:), undersore(_) or hyphen(-)");
840 }
841 if ($this->mpdf->onlyCoreFonts) {
842 $value = $this->Win1252ToPDFDocEncoding($value);
843 $default = $this->Win1252ToPDFDocEncoding($default);
844 $title = $this->Win1252ToPDFDocEncoding($title);
845 } else {
846 if (isset($this->mpdf->CurrentFont['subset'])) {
847 $this->mpdf->UTF8StringToArray($value, true); // Add characters to font subset
848 $this->mpdf->UTF8StringToArray($default, true); // Add characters to font subset
849 $this->mpdf->UTF8StringToArray($title, true); // Add characters to font subset
850 }
851 if ($value)
852 $value = $this->mpdf->UTF8ToUTF16BE($value, true);
853 if ($default)
854 $default = $this->mpdf->UTF8ToUTF16BE($default, true);
855 $title = $this->mpdf->UTF8ToUTF16BE($title, true);
856 }
857 if ($background_col) {
858 $bg_c = $this->mpdf->SetColor($background_col, 'CodeOnly');
859 } else {
860 $bg_c = $this->form_background_color;
861 }
862 if ($border_col) {
863 $bc_c = $this->mpdf->SetColor($border_col, 'CodeOnly');
864 } else {
865 $bc_c = $this->form_border_color;
866 }
867 $f = array('n' => $this->formn,
868 'typ' => 'Tx',
869 'page' => $this->mpdf->page,
870 'x' => $this->mpdf->x,
871 'y' => $this->mpdf->y,
872 'w' => $w,
873 'h' => $h,
874 'T' => $name,
875 'FF' => $flags,
876 'V' => $value,
877 'DV' => $default,
878 'TU' => $title,
879 'hidden' => $hidden,
880 'Q' => $align,
881 'maxlen' => $maxlen,
882 'BS_W' => $this->form_border_width,
883 'BS_S' => $this->form_border_style,
884 'BC_C' => $bc_c,
885 'BG_C' => $bg_c,
886 'style' => array(
887 'font' => $this->mpdf->FontFamily,
888 'fontsize' => $this->mpdf->FontSizePt,
889 'fontcolor' => $this->mpdf->TextColor,
890 )
891 );
892 if (is_array($js) && count($js) > 0) {
893 $this->SetFormTextJS($name, $js);
894 } // mPDF 5.3.25
895 if ($this->mpdf->keep_block_together) {
896 $this->mpdf->ktForms[] = $f;
897 } else if ($this->mpdf->writingHTMLheader || $this->mpdf->writingHTMLfooter) {
898 $this->mpdf->HTMLheaderPageForms[] = $f;
899 } else {
900 if ($this->mpdf->ColActive) {
901 $this->mpdf->columnbuffer[] = array('s' => 'ACROFORM', 'col' => $this->mpdf->CurrCol, 'x' => $this->mpdf->x, 'y' => $this->mpdf->y,
902 'h' => $h);
903 $this->mpdf->columnForms[$this->mpdf->CurrCol][INTVAL($this->mpdf->x)][INTVAL($this->mpdf->y)] = $this->formn;
904 }
905 $this->forms[$this->formn] = $f;
906 }
907 if (!in_array($this->mpdf->FontFamily, $this->form_fonts)) {
908 $this->form_fonts[] = $this->mpdf->FontFamily;
909 $this->mpdf->fonts[$this->mpdf->FontFamily]['used'] = true;
910 }
911 if (!$hidden)
912 $this->mpdf->x += $w;
913 }
914
915 function SetFormChoice($w, $h, $name, $flags, $array, $align = 'L', $js = '')
916 {
917 $this->formn++;
918 if ($this->mpdf->blk[$this->mpdf->blklvl]['direction'] == 'rtl') {
919 $align = '2';
920 } else {
921 $align = '0';
922 }
923 if (!preg_match('/^[a-zA-Z0-9_:\-]+$/', $name)) {
924 $this->mpdf->Error("Field [" . $name . "] must have a name attribute, which can only contain letters, numbers, colon(:), undersore(_) or hyphen(-)");
925 }
926 if ($this->mpdf->onlyCoreFonts) {
927 for ($i = 0; $i < count($array['VAL']); $i++) {
928 $array['VAL'][$i] = $this->Win1252ToPDFDocEncoding($array['VAL'][$i]);
929 $array['OPT'][$i] = $this->Win1252ToPDFDocEncoding($array['OPT'][$i]);
930 }
931 } else {
932 for ($i = 0; $i < count($array['VAL']); $i++) {
933 if (isset($this->mpdf->CurrentFont['subset'])) {
934 $this->mpdf->UTF8StringToArray($array['VAL'][$i], true); // Add characters to font subset
935 $this->mpdf->UTF8StringToArray($array['OPT'][$i], true); // Add characters to font subset
936 }
937 if ($array['VAL'][$i])
938 $array['VAL'][$i] = $this->mpdf->UTF8ToUTF16BE($array['VAL'][$i], true);
939 if ($array['OPT'][$i])
940 $array['OPT'][$i] = $this->mpdf->UTF8ToUTF16BE($array['OPT'][$i], true);
941 }
942 }
943 $f = array('n' => $this->formn,
944 'typ' => 'Ch',
945 'page' => $this->mpdf->page,
946 'x' => $this->mpdf->x,
947 'y' => $this->mpdf->y,
948 'w' => $w,
949 'h' => $h,
950 'T' => $name,
951 'OPT' => $array,
952 'FF' => $flags,
953 'Q' => $align,
954 'BS_W' => $this->form_border_width,
955 'BS_S' => $this->form_border_style,
956 'BC_C' => $this->form_border_color,
957 'BG_C' => $this->form_background_color,
958 'style' => array(
959 'font' => $this->mpdf->FontFamily,
960 'fontsize' => $this->mpdf->FontSizePt,
961 'fontcolor' => $this->mpdf->TextColor,
962 )
963 );
964 if ($js) {
965 $this->SetFormChoiceJS($name, $js);
966 }
967 if ($this->mpdf->keep_block_together) {
968 $this->mpdf->ktForms[] = $f;
969 } else if ($this->mpdf->writingHTMLheader || $this->mpdf->writingHTMLfooter) {
970 $this->mpdf->HTMLheaderPageForms[] = $f;
971 } else {
972 if ($this->mpdf->ColActive) {
973 $this->mpdf->columnbuffer[] = array('s' => 'ACROFORM', 'col' => $this->mpdf->CurrCol, 'x' => $this->mpdf->x, 'y' => $this->mpdf->y,
974 'h' => $h);
975 $this->mpdf->columnForms[$this->mpdf->CurrCol][INTVAL($this->mpdf->x)][INTVAL($this->mpdf->y)] = $this->formn;
976 }
977 $this->forms[$this->formn] = $f;
978 }
979 if (!in_array($this->mpdf->FontFamily, $this->form_fonts)) {
980 $this->form_fonts[] = $this->mpdf->FontFamily;
981 $this->mpdf->fonts[$this->mpdf->FontFamily]['used'] = true;
982 }
983 $this->mpdf->x += $w;
984 }
985
986 // CHECKBOX
987 function SetCheckBox($w, $h, $name, $value, $title = '', $checked = false, $flags = array(), $disabled = false)
988 {
989 $this->SetFormButton($w, $h, $name, $value, 'checkbox', $title, $flags, $checked, $disabled);
990 $this->mpdf->x += $w;
991 }
992
993 // RADIO
994 function SetRadio($w, $h, $name, $value, $title = '', $checked = false, $flags = array(), $disabled = false)
995 {
996 $this->SetFormButton($w, $h, $name, $value, 'radio', $title, $flags, $checked, $disabled);
997 $this->mpdf->x += $w;
998 }
999
1000 function SetFormReset($w, $h, $name, $value = 'Reset', $title = '', $flags = array(), $background_col = false, $border_col = false, $noprint = false)
1001 {
1002 if (!$name) {
1003 $name = 'Reset';
1004 }
1005 $this->SetFormButton($w, $h, $name, $value, 'reset', $title, $flags, false, false, $background_col, $border_col, $noprint);
1006 $this->mpdf->x += $w;
1007 }
1008
1009 function SetJSButton($w, $h, $name, $value, $js, $image_id = 0, $title = '', $flags = array(), $indexed = false, $background_col = false, $border_col = false, $noprint = false)
1010 {
1011 $this->SetFormButton($w, $h, $name, $value, 'js_button', $title, $flags, false, false, $background_col, $border_col, $noprint);
1012 // pos => 1 = no caption, icon only; 0 = caption only
1013 if ($image_id) {
1014 $this->form_button_icon[$this->mpdf->_escape($name)] = array(
1015 'pos' => 1,
1016 'image_id' => $image_id,
1017 'Indexed' => $indexed,
1018 );
1019 }
1020 if ($js) {
1021 $this->SetFormButtonJS($name, $js);
1022 }
1023 $this->mpdf->x += $w;
1024 }
1025
1026 function SetFormSubmit($w, $h, $name, $value = 'Submit', $url, $title = '', $typ = 'html', $method = 'POST', $flags = array(), $background_col = false, $border_col = false, $noprint = false)
1027 {
1028 if (!$name) {
1029 $name = 'Submit';
1030 }
1031 $this->SetFormButton($w, $h, $name, $value, 'submit', $title, $flags, false, false, $background_col, $border_col, $noprint);
1032 $this->forms[$this->formn]['URL'] = $url;
1033 $this->forms[$this->formn]['method'] = $method;
1034 $this->forms[$this->formn]['exporttype'] = $typ;
1035 $this->mpdf->x += $w;
1036 }
1037
1038 function SetFormButtonText($ca, $rc = '', $ac = '')
1039 {
1040 if ($this->mpdf->onlyCoreFonts) {
1041 $ca = $this->Win1252ToPDFDocEncoding($ca);
1042 if ($rc)
1043 $rc = $this->Win1252ToPDFDocEncoding($rc);
1044 if ($ac)
1045 $ac = $this->Win1252ToPDFDocEncoding($ac);
1046 }
1047 else {
1048 if (isset($this->mpdf->CurrentFont['subset'])) {
1049 $this->mpdf->UTF8StringToArray($ca, true); // Add characters to font subset
1050 }
1051 $ca = $this->mpdf->UTF8ToUTF16BE($ca, true);
1052 if ($rc) {
1053 if (isset($this->mpdf->CurrentFont['subset'])) {
1054 $this->mpdf->UTF8StringToArray($rc, true);
1055 }
1056 $rc = $this->mpdf->UTF8ToUTF16BE($rc, true);
1057 }
1058 if ($ac) {
1059 if (isset($this->mpdf->CurrentFont['subset'])) {
1060 $this->mpdf->UTF8StringToArray($ac, true);
1061 }
1062 $ac = $this->mpdf->UTF8ToUTF16BE($ac, true);
1063 }
1064 }
1065 $this->form_button_text = $ca;
1066 $this->form_button_text_over = $rc ? $rc : $ca;
1067 $this->form_button_text_click = $ac ? $ac : $ca;
1068 }
1069
1070 function SetFormButton($bb, $hh, $name, $value, $type, $title = '', $flags = array(), $checked = false, $disabled = false, $background_col = false, $border_col = false, $noprint = false)
1071 {
1072 $this->formn++;
1073 if (!preg_match('/^[a-zA-Z0-9_:\-]+$/', $name)) {
1074 $this->mpdf->Error("Field [" . $name . "] must have a name attribute, which can only contain letters, numbers, colon(:), undersore(_) or hyphen(-)");
1075 }
1076 if (!$this->mpdf->onlyCoreFonts) {
1077 if (isset($this->mpdf->CurrentFont['subset'])) {
1078 $this->mpdf->UTF8StringToArray($title, true); // Add characters to font subset
1079 $this->mpdf->UTF8StringToArray($value, true); // Add characters to font subset
1080 }
1081 $title = $this->mpdf->UTF8ToUTF16BE($title, true);
1082 if ($type == 'checkbox') {
1083 $uvalue = $this->mpdf->UTF8ToUTF16BE($value, true);
1084 } else if ($type == 'radio') {
1085 $uvalue = $this->mpdf->UTF8ToUTF16BE($value, true);
1086 $value = mb_convert_encoding($value, 'Windows-1252', 'UTF-8');
1087 } else {
1088 $value = $this->mpdf->UTF8ToUTF16BE($value, true);
1089 $uvalue = $value;
1090 }
1091 } else {
1092 $title = $this->Win1252ToPDFDocEncoding($title);
1093 $value = $this->Win1252ToPDFDocEncoding($value); //// ??? not needed
1094 $uvalue = mb_convert_encoding($value, 'UTF-8', 'Windows-1252');
1095 $uvalue = $this->mpdf->UTF8ToUTF16BE($uvalue, true);
1096 }
1097 if ($type == 'radio' || $type == 'checkbox') {
1098 if (!preg_match('/^[a-zA-Z0-9_:\-\.]+$/', $value)) {
1099 $this->mpdf->Error("Field '" . $name . "' must have a value, which can only contain letters, numbers, colon(:), undersore(_), hyphen(-) or period(.)");
1100 }
1101 }
1102 if ($type == 'radio') {
1103 if (!isset($this->form_radio_groups[$name])) {
1104 $this->form_radio_groups[$name] = array(
1105 'page' => $this->mpdf->page,
1106 'kids' => array(),
1107 );
1108 }
1109 $this->form_radio_groups[$name]['kids'][] = array(
1110 'n' => $this->formn, 'V' => $value, 'OPT' => $uvalue, 'disabled' => $disabled
1111 );
1112 if ($checked) {
1113 $this->form_radio_groups[$name]['on'] = $value;
1114 }
1115 // Disable the whole radio group if one is disabled, because of inconsistency in PDF readers
1116 if ($disabled) {
1117 $this->form_radio_groups[$name]['disabled'] = true;
1118 }
1119 }
1120 if ($type == 'checkbox') {
1121 $this->form_checkboxes = true;
1122 }
1123 if ($checked) {
1124 $activ = 1;
1125 } else {
1126 $activ = 0;
1127 }
1128 if ($background_col) {
1129 $bg_c = $this->mpdf->SetColor($background_col, 'CodeOnly');
1130 } else {
1131 $bg_c = $this->form_button_background_color;
1132 }
1133 if ($border_col) {
1134 $bc_c = $this->mpdf->SetColor($border_col, 'CodeOnly');
1135 } else {
1136 $bc_c = $this->form_button_border_color;
1137 }
1138 $f = array('n' => $this->formn,
1139 'typ' => 'Bt',
1140 'page' => $this->mpdf->page,
1141 'subtype' => $type,
1142 'x' => $this->mpdf->x,
1143 'y' => $this->mpdf->y,
1144 'w' => $bb,
1145 'h' => $hh,
1146 'T' => $name,
1147 'V' => $value,
1148 'OPT' => $uvalue,
1149 'TU' => $title,
1150 'FF' => $flags,
1151 'CA' => $this->form_button_text,
1152 'RC' => $this->form_button_text_over,
1153 'AC' => $this->form_button_text_click,
1154 'BS_W' => $this->form_button_border_width,
1155 'BS_S' => $this->form_button_border_style,
1156 'BC_C' => $bc_c,
1157 'BG_C' => $bg_c,
1158 'activ' => $activ,
1159 'disabled' => $disabled,
1160 'noprint' => $noprint,
1161 'style' => array(
1162 'font' => $this->mpdf->FontFamily,
1163 'fontsize' => $this->mpdf->FontSizePt,
1164 'fontcolor' => $this->mpdf->TextColor,
1165 )
1166 );
1167 if ($this->mpdf->keep_block_together) {
1168 $this->mpdf->ktForms[] = $f;
1169 } else if ($this->mpdf->writingHTMLheader || $this->mpdf->writingHTMLfooter) {
1170 $this->mpdf->HTMLheaderPageForms[] = $f;
1171 } else {
1172 if ($this->mpdf->ColActive) {
1173 $this->mpdf->columnbuffer[] = array('s' => 'ACROFORM', 'col' => $this->mpdf->CurrCol, 'x' => $this->mpdf->x, 'y' => $this->mpdf->y,
1174 'h' => $hh);
1175 $this->mpdf->columnForms[$this->mpdf->CurrCol][INTVAL($this->mpdf->x)][INTVAL($this->mpdf->y)] = $this->formn;
1176 }
1177 $this->forms[$this->formn] = $f;
1178 }
1179 if (!in_array($this->mpdf->FontFamily, $this->form_fonts)) {
1180 $this->form_fonts[] = $this->mpdf->FontFamily;
1181 $this->mpdf->fonts[$this->mpdf->FontFamily]['used'] = true;
1182 }
1183
1184 $this->form_button_text = NULL;
1185 $this->form_button_text_over = NULL;
1186 $this->form_button_text_click = NULL;
1187 }
1188
1189 function SetFormBorderWidth($string)
1190 {
1191 switch ($string) {
1192 case 'S': $this->form_border_width = '1';
1193 break;
1194 case 'M': $this->form_border_width = '2';
1195 break;
1196 case 'B': $this->form_border_width = '3';
1197 break;
1198 case '0': $this->form_border_width = '0';
1199 break;
1200 default: $this->form_border_width = '0';
1201 break;
1202 }
1203 }
1204
1205 function SetFormBorderStyle($string)
1206 {
1207 switch ($string) {
1208 case 'S': $this->form_border_style = 'S';
1209 break;
1210 case 'D': $this->form_border_style = 'D /D [3]';
1211 break;
1212 case 'B': $this->form_border_style = 'B';
1213 break;
1214 case 'I': $this->form_border_style = 'I';
1215 break;
1216 case 'U': $this->form_border_style = 'U';
1217 break;
1218 default: $this->form_border_style = 'B';
1219 break;
1220 }
1221 }
1222
1223 function SetFormBorderColor($r, $g = -1, $b = -1)
1224 {
1225 if (($r == 0 and $g == 0 and $b == 0) || $g == -1)
1226 $this->form_border_color = sprintf('%.3F', $r / 255);
1227 else
1228 $this->form_border_color = sprintf('%.3F %.3F %.3F', $r / 255, $g / 255, $b / 255);
1229 }
1230
1231 function SetFormBackgroundColor($r, $g = -1, $b = -1)
1232 {
1233 if (($r == 0 and $g == 0 and $b == 0) || $g == -1)
1234 $this->form_background_color = sprintf('%.3F', $r / 255);
1235 else
1236 $this->form_background_color = sprintf('%.3F %.3F %.3F', $r / 255, $g / 255, $b / 255);
1237 }
1238
1239 function SetFormD($W, $S, $BC, $BG)
1240 {
1241 $this->SetFormBorderWidth($W);
1242 $this->SetFormBorderStyle($S);
1243 $this->SetFormBorderColor($BC);
1244 $this->SetFormBackgroundColor($BG);
1245 }
1246
1247 function _setflag($array)
1248 {
1249 $flag = 0;
1250 foreach ($array as $val) {
1251 $flag += 1 << ($val - 1);
1252 }
1253 return $flag;
1254 }
1255
1256 function _form_rect($x, $y, $w, $h, $hPt)
1257 {
1258 $x = $x * _MPDFK;
1259 $y = $hPt - ($y * _MPDFK);
1260 $x2 = $x + ($w * _MPDFK);
1261 $y2 = $y - ($h * _MPDFK);
1262 $rect = sprintf('%.3F %.3F %.3F %.3F', $x, $y2, $x2, $y);
1263 return $rect;
1264 }
1265
1266 function _put_button_icon($array, $w, $h)
1267 {
1268 if (isset($array['image_id'])) {
1269 $info = false;
1270 foreach ($this->mpdf->images AS $iid => $img) {
1271 if ($img['i'] == $array['image_id']) {
1272 $info = $this->mpdf->images[$iid];
1273 break;
1274 }
1275 }
1276 }
1277 if (!$info) {
1278 throw new MpdfException("Cannot find Button image");
1279 }
1280 $this->mpdf->_newobj();
1281 $this->mpdf->_out('<<');
1282 $this->mpdf->_out('/Type /XObject');
1283 $this->mpdf->_out('/Subtype /Image');
1284 $this->mpdf->_out('/BBox [0 0 1 1]');
1285 $this->mpdf->_out('/Length ' . strlen($info['data']));
1286 $this->mpdf->_out('/BitsPerComponent ' . $info['bpc']);
1287 if ($info['cs'] == 'Indexed') {
1288 $this->mpdf->_out('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3 - 1) . ' ' . ($this->mpdf->n + 1) . ' 0 R]');
1289 } else {
1290 $this->mpdf->_out('/ColorSpace /' . $info['cs']);
1291 if ($info['cs'] == 'DeviceCMYK')
1292 if ($info['type'] == 'jpg') {
1293 $this->mpdf->_out('/Decode [1 0 1 0 1 0 1 0]');
1294 }
1295 }
1296 if (isset($info['f']))
1297 $this->mpdf->_out('/Filter /' . $info['f']);
1298 if (isset($info['parms']))
1299 $this->mpdf->_out($info['parms']);
1300 $this->mpdf->_out('/Width ' . $info['w']);
1301 $this->mpdf->_out('/Height ' . $info['h']);
1302 $this->mpdf->_out('>>');
1303 $this->mpdf->_putstream($info['data']);
1304 $this->mpdf->_out('endobj');
1305 unset($array);
1306 //Palette
1307 if ($info['cs'] == 'Indexed') {
1308 $filter = ($this->mpdf->compress) ? '/Filter /FlateDecode ' : '';
1309 $this->mpdf->_newobj();
1310 $pal = ($this->mpdf->compress) ? gzcompress($info['pal']) : $info['pal'];
1311 $this->mpdf->_out('<<' . $filter . '/Length ' . strlen($pal) . '>>');
1312 $this->mpdf->_putstream($pal);
1313 $this->mpdf->_out('endobj');
1314 }
1315 }
1316
1317 function _putform_bt($form, $hPt)
1318 {
1319 $cc = 0;
1320 $put_xobject = 0;
1321 $put_js = 0;
1322 $put_icon = 0;
1323 $this->mpdf->_newobj();
1324 $n = $this->mpdf->n;
1325 if ($form['subtype'] != 'radio')
1326 $this->pdf_acro_array .= $n . ' 0 R '; // Add to /Field element
1327 $this->forms[$form['n']]['obj'] = $n;
1328 $this->mpdf->_out('<<');
1329 $this->mpdf->_out('/Type /Annot ');
1330 $this->mpdf->_out('/Subtype /Widget');
1331 $this->mpdf->_out('/NM ' . $this->mpdf->_textstring(sprintf('%04u-%04u', $n, (7000 + $form['n']))));
1332 $this->mpdf->_out('/M ' . $this->mpdf->_textstring('D:' . date('YmdHis')));
1333 $this->mpdf->_out('/Rect [ ' . $this->_form_rect($form['x'], $form['y'], $form['w'], $form['h'], $hPt) . ' ]');
1334 $form['noprint'] ? $this->mpdf->_out('/F 0 ') : $this->mpdf->_out('/F 4 ');
1335 $this->mpdf->_out('/FT /Btn ');
1336 $this->mpdf->_out('/H /P ');
1337 if ($form['subtype'] != 'radio') // mPDF 5.3.23
1338 $this->mpdf->_out('/T ' . $this->mpdf->_textstring($form['T']));
1339 $this->mpdf->_out('/TU ' . $this->mpdf->_textstring($form['TU']));
1340 if (isset($this->form_button_icon[$form['T']])) {
1341 $form['BS_W'] = 0;
1342 }
1343 if ($form['BS_W'] == 0) {
1344 $form['BC_C'] = $form['BG_C'];
1345 }
1346 $bstemp = '';
1347 $bstemp .= '/W ' . $form['BS_W'] . ' ';
1348 $bstemp .= '/S /' . $form['BS_S'] . ' ';
1349 $temp = '';
1350 $temp .= '/BC [ ' . $form['BC_C'] . " ] ";
1351 $temp .= '/BG [ ' . $form['BG_C'] . " ] ";
1352 if ($form['subtype'] == 'checkbox') {
1353 if ($form['disabled']) {
1354 $radio_color = '0.5 0.5 0.5';
1355 $radio_background_color = '0.9 0.9 0.9';
1356 } else {
1357 $radio_color = $this->form_radio_color;
1358 $radio_background_color = $this->form_radio_background_color;
1359 }
1360 $temp = '';
1361 $temp .= '/BC [ ' . $radio_color . " ] ";
1362 $temp .= '/BG [ ' . $radio_background_color . " ] ";
1363 $this->mpdf->_out("/BS << /W 1 /S /S >>");
1364 $this->mpdf->_out("/MK << $temp >>");
1365 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']));
1366 if ($form['activ']) {
1367 $this->mpdf->_out('/V /' . $this->mpdf->_escape($form['V']) . ' ');
1368 $this->mpdf->_out('/DV /' . $this->mpdf->_escape($form['V']) . ' ');
1369 $this->mpdf->_out('/AS /' . $this->mpdf->_escape($form['V']) . ' ');
1370 } else {
1371 $this->mpdf->_out('/AS /Off ');
1372 }
1373 if ($this->formUseZapD) {
1374 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts['czapfdingbats']['i'] . ' 0 Tf ' . $radio_color . ' rg)');
1375 $this->mpdf->_out("/AP << /N << /" . $this->mpdf->_escape($form['V']) . " " . ($this->mpdf->n + 1) . " 0 R /Off /Off >> >>");
1376 } else {
1377 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$this->mpdf->CurrentFont['fontkey']]['i'] . ' 0 Tf ' . $radio_color . ' rg)');
1378 $this->mpdf->_out("/AP << /N << /" . $this->mpdf->_escape($form['V']) . " " . ($this->mpdf->n + 1) . " 0 R /Off " . ($this->mpdf->n + 2) . " 0 R >> >>");
1379 }
1380 $this->mpdf->_out('/Opt [ ' . $this->mpdf->_textstring($form['OPT']) . ' ' . $this->mpdf->_textstring($form['OPT']) . ' ]');
1381 }
1382
1383
1384 if ($form['subtype'] == 'radio') {
1385 if ((isset($form['disabled']) && $form['disabled']) || (isset($this->form_radio_groups[$form['T']]['disabled']) && $this->form_radio_groups[$form['T']]['disabled'])) {
1386 $radio_color = '0.5 0.5 0.5';
1387 $radio_background_color = '0.9 0.9 0.9';
1388 } else {
1389 $radio_color = $this->form_radio_color;
1390 $radio_background_color = $this->form_radio_background_color;
1391 }
1392 $this->mpdf->_out('/Parent ' . $this->form_radio_groups[$form['T']]['obj_id'] . ' 0 R ');
1393 $temp = '';
1394 $temp .= '/BC [ ' . $radio_color . " ] ";
1395 $temp .= '/BG [ ' . $radio_background_color . " ] ";
1396 $this->mpdf->_out("/BS << /W 1 /S /S >>");
1397 $this->mpdf->_out('/MK << ' . $temp . ' >> ');
1398 $form['FF'][] = 16; // Radiobutton
1399 $form['FF'][] = 15; // NoToggleOff - must be same as radio button group setting?
1400 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']));
1401 if ($this->formUseZapD)
1402 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts['czapfdingbats']['i'] . ' 0 Tf ' . $radio_color . ' rg)');
1403 else
1404 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$this->mpdf->CurrentFont['fontkey']]['i'] . ' 0 Tf ' . $radio_color . ' rg)');
1405 $this->mpdf->_out("/AP << /N << /" . $this->mpdf->_escape($form['V']) . " " . ($this->mpdf->n + 1) . " 0 R /Off " . ($this->mpdf->n + 2) . " 0 R >> >>");
1406 if ($form['activ']) {
1407 $this->mpdf->_out('/V /' . $this->mpdf->_escape($form['V']) . ' ');
1408 $this->mpdf->_out('/DV /' . $this->mpdf->_escape($form['V']) . ' ');
1409 $this->mpdf->_out('/AS /' . $this->mpdf->_escape($form['V']) . ' ');
1410 } else {
1411 $this->mpdf->_out('/AS /Off ');
1412 }
1413 $this->mpdf->_out("/AP << /N << /" . $this->mpdf->_escape($form['V']) . " " . ($this->mpdf->n + 1) . " 0 R /Off " . ($this->mpdf->n + 2) . " 0 R >> >>");
1414 // $this->mpdf->_out('/Opt [ '.$this->mpdf->_textstring($form['OPT']).' '.$this->mpdf->_textstring($form['OPT']).' ]');
1415 }
1416
1417 if ($form['subtype'] == 'reset') {
1418 $temp .= $form['CA'] ? '/CA ' . $this->mpdf->_textstring($form['CA']) . ' ' : '/CA ' . $this->mpdf->_textstring($form['T']) . ' ';
1419 $temp .= $form['RC'] ? '/RC ' . $this->mpdf->_textstring($form['RC']) . ' ' : '/RC ' . $this->mpdf->_textstring($form['T']) . ' ';
1420 $temp .= $form['AC'] ? '/AC ' . $this->mpdf->_textstring($form['AC']) . ' ' : '/AC ' . $this->mpdf->_textstring($form['T']) . ' ';
1421 $this->mpdf->_out("/BS << $bstemp >>");
1422 $this->mpdf->_out('/MK << ' . $temp . ' >>');
1423 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$form['style']['font']]['i'] . ' ' . $form['style']['fontsize'] . ' Tf ' . $form['style']['fontcolor'] . ')');
1424 $this->mpdf->_out('/AA << /D << /S /ResetForm /Flags 1 >> >>');
1425 $form['FF'][] = 17;
1426 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']));
1427 }
1428
1429
1430 if ($form['subtype'] == 'submit') {
1431 $temp .= $form['CA'] ? '/CA ' . $this->mpdf->_textstring($form['CA']) . ' ' : '/CA ' . $this->mpdf->_textstring($form['T']) . ' ';
1432 $temp .= $form['RC'] ? '/RC ' . $this->mpdf->_textstring($form['RC']) . ' ' : '/RC ' . $this->mpdf->_textstring($form['T']) . ' ';
1433 $temp .= $form['AC'] ? '/AC ' . $this->mpdf->_textstring($form['AC']) . ' ' : '/AC ' . $this->mpdf->_textstring($form['T']) . ' ';
1434 $this->mpdf->_out("/BS << $bstemp >>");
1435 $this->mpdf->_out("/MK << $temp >>");
1436 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$form['style']['font']]['i'] . ' ' . $form['style']['fontsize'] . ' Tf ' . $form['style']['fontcolor'] . ')');
1437 // Bit 4 (8) = useGETmethod else use POST
1438 // Bit 3 (4) = HTML export format (charset chosen by Adobe)--- OR ---
1439 // Bit 6 (32) = XFDF export format (form of XML in UTF-8)
1440 if ($form['exporttype'] == 'xfdf') {
1441 $flag = 32;
1442 } // 'xfdf' or 'html'
1443 else {
1444 if ($form['method'] == 'GET') {
1445 $flag = 12;
1446 } else {
1447 $flag = 4;
1448 }
1449 }
1450 // Bit 2 (2) = IncludeNoValueFields
1451 if ($this->formSubmitNoValueFields)
1452 $flag += 2;
1453 // To submit a value, needs to be in /AP dictionary, AND this object must contain a /Fields entry
1454 // listing all fields to output
1455 $this->mpdf->_out('/AA << /D << /S /SubmitForm /F (' . $form['URL'] . ') /Flags ' . $flag . ' >> >>');
1456 $form['FF'][] = 17;
1457 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']));
1458 }
1459
1460 if ($form['subtype'] == 'js_button') {
1461 // Icon / image
1462 if (isset($this->form_button_icon[$form['T']])) {
1463 $cc++;
1464 $temp .= '/TP ' . $this->form_button_icon[$form['T']]['pos'] . ' ';
1465 $temp .= '/I ' . ($cc + $this->mpdf->n) . ' 0 R '; // Normal icon
1466 $temp .= '/RI ' . ($cc + $this->mpdf->n) . ' 0 R '; // onMouseOver
1467 $temp .= '/IX ' . ($cc + $this->mpdf->n) . ' 0 R '; // onClick / onMouseDown
1468 $temp .= '/IF << /SW /A /S /A /A [0.0 0.0] >> '; // Icon fit dictionary
1469 if ($this->form_button_icon[$form['T']]['Indexed']) {
1470 $cc++;
1471 }
1472 $put_icon = 1;
1473 }
1474 $temp .= $form['CA'] ? '/CA ' . $this->mpdf->_textstring($form['CA']) . ' ' : '/CA ' . $this->mpdf->_textstring($form['T']) . ' ';
1475 $temp .= $form['RC'] ? '/RC ' . $this->mpdf->_textstring($form['RC']) . ' ' : '/RC ' . $this->mpdf->_textstring($form['T']) . ' ';
1476 $temp .= $form['AC'] ? '/AC ' . $this->mpdf->_textstring($form['AC']) . ' ' : '/AC ' . $this->mpdf->_textstring($form['T']) . ' ';
1477 $this->mpdf->_out("/BS << $bstemp >>");
1478 $this->mpdf->_out("/MK << $temp >>");
1479 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$form['style']['font']]['i'] . ' ' . $form['style']['fontsize'] . ' Tf ' . $form['style']['fontcolor'] . ')');
1480 $form['FF'][] = 17;
1481 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']));
1482 // Javascript
1483 if (isset($this->array_form_button_js[$form['T']])) {
1484 $cc++;
1485 $this->mpdf->_out("/AA << /D " . ($cc + $this->mpdf->n) . " 0 R >>");
1486 $put_js = 1;
1487 }
1488 }
1489
1490 $this->mpdf->_out('>>');
1491 $this->mpdf->_out('endobj');
1492
1493 // additional objects
1494 // obj icon
1495 if ($put_icon == 1) {
1496 $this->_put_button_icon($this->form_button_icon[$form['T']], $form['w'], $form['h']);
1497 $put_icon = NULL;
1498 }
1499 // obj + 1
1500 if ($put_js == 1) {
1501 $this->mpdf->_set_object_javascript($this->array_form_button_js[$form['T']]['js']);
1502 unset($this->array_form_button_js[$form['T']]);
1503 $put_js = NULL;
1504 }
1505
1506 // RADIO and CHECK BOX appearance streams
1507 $filter = ($this->mpdf->compress) ? '/Filter /FlateDecode ' : '';
1508 if ($form['subtype'] == 'radio') {
1509 // output 2 appearance streams for radio buttons on/off
1510 if ($this->formUseZapD) {
1511 $fs = sprintf('%.3F', $form['style']['fontsize'] * 1.25);
1512 $fi = 'czapfdingbats';
1513 $r_on = 'q ' . $radio_color . ' rg BT /F' . $this->mpdf->fonts[$fi]['i'] . ' ' . $fs . ' Tf 0 0 Td (4) Tj ET Q';
1514 $r_off = 'q ' . $radio_color . ' rg BT /F' . $this->mpdf->fonts[$fi]['i'] . ' ' . $fs . ' Tf 0 0 Td (8) Tj ET Q';
1515 } else {
1516 $matrix = sprintf('%.3F 0 0 %.3F 0 %.3F', $form['style']['fontsize'] * 1.33 / 10, $form['style']['fontsize'] * 1.25 / 10, $form['style']['fontsize']);
1517 $fill = $radio_background_color . ' rg 3.778 -7.410 m 2.800 -7.410 1.947 -7.047 1.225 -6.322 c 0.500 -5.600 0.138 -4.747 0.138 -3.769 c 0.138 -2.788 0.500 -1.938 1.225 -1.213 c 1.947 -0.491 2.800 -0.128 3.778 -0.128 c 4.757 -0.128 5.610 -0.491 6.334 -1.213 c 7.056 -1.938 7.419 -2.788 7.419 -3.769 c 7.419 -4.747 7.056 -5.600 6.334 -6.322 c 5.610 -7.047 4.757 -7.410 3.778 -7.410 c h f ';
1518 $circle = '3.778 -6.963 m 4.631 -6.963 5.375 -6.641 6.013 -6.004 c 6.653 -5.366 6.972 -4.619 6.972 -3.769 c 6.972 -2.916 6.653 -2.172 6.013 -1.532 c 5.375 -0.894 4.631 -0.576 3.778 -0.576 c 2.928 -0.576 2.182 -0.894 1.544 -1.532 c 0.904 -2.172 0.585 -2.916 0.585 -3.769 c 0.585 -4.619 0.904 -5.366 1.544 -6.004 c 2.182 -6.641 2.928 -6.963 3.778 -6.963 c h 3.778 -7.410 m 2.800 -7.410 1.947 -7.047 1.225 -6.322 c 0.500 -5.600 0.138 -4.747 0.138 -3.769 c 0.138 -2.788 0.500 -1.938 1.225 -1.213 c 1.947 -0.491 2.800 -0.128 3.778 -0.128 c 4.757 -0.128 5.610 -0.491 6.334 -1.213 c 7.056 -1.938 7.419 -2.788 7.419 -3.769 c 7.419 -4.747 7.056 -5.600 6.334 -6.322 c 5.610 -7.047 4.757 -7.410 3.778 -7.410 c h f ';
1519 $r_on = 'q ' . $matrix . ' cm ' . $fill . $radio_color . ' rg ' . $circle . ' ' . $radio_color . ' rg
1520 5.184 -5.110 m 4.800 -5.494 4.354 -5.685 3.841 -5.685 c 3.331 -5.685 2.885 -5.494 2.501 -5.110 c 2.119 -4.725 1.925 -4.279 1.925 -3.769 c 1.925 -3.257 2.119 -2.810 2.501 -2.429 c 2.885 -2.044 3.331 -1.853 3.841 -1.853 c 4.354 -1.853 4.800 -2.044 5.184 -2.429 c 5.566 -2.810 5.760 -3.257 5.760 -3.769 c 5.760 -4.279 5.566 -4.725 5.184 -5.110 c h
1521 f Q ';
1522 $r_off = 'q ' . $matrix . ' cm ' . $fill . $radio_color . ' rg ' . $circle . ' Q ';
1523 }
1524
1525 $this->mpdf->_newobj();
1526 $p = ($this->mpdf->compress) ? gzcompress($r_on) : $r_on;
1527 $this->mpdf->_out('<<' . $filter . '/Length ' . strlen($p) . ' /Resources 2 0 R>>');
1528 $this->mpdf->_putstream($p);
1529 $this->mpdf->_out('endobj');
1530
1531 $this->mpdf->_newobj();
1532 $p = ($this->mpdf->compress) ? gzcompress($r_off) : $r_off;
1533 $this->mpdf->_out('<<' . $filter . '/Length ' . strlen($p) . ' /Resources 2 0 R>>');
1534 $this->mpdf->_putstream($p);
1535 $this->mpdf->_out('endobj');
1536 }
1537 if ($form['subtype'] == 'checkbox') {
1538 // First output appearance stream for check box on
1539 if ($this->formUseZapD) {
1540 $fs = sprintf('%.3F', $form['style']['fontsize'] * 1.25);
1541 $fi = 'czapfdingbats';
1542 $cb_on = 'q ' . $radio_color . ' rg BT /F' . $this->mpdf->fonts[$fi]['i'] . ' ' . $fs . ' Tf 0 0 Td (4) Tj ET Q';
1543 $cb_off = 'q ' . $radio_color . ' rg BT /F' . $this->mpdf->fonts[$fi]['i'] . ' ' . $fs . ' Tf 0 0 Td (8) Tj ET Q';
1544 } else {
1545 $matrix = sprintf('%.3F 0 0 %.3F 0 %.3F', $form['style']['fontsize'] * 1.33 / 10, $form['style']['fontsize'] * 1.25 / 10, $form['style']['fontsize']);
1546 $fill = $radio_background_color . ' rg 7.395 -0.070 m 7.395 -7.344 l 0.121 -7.344 l 0.121 -0.070 l 7.395 -0.070 l h f ';
1547 $square = '0.508 -6.880 m 6.969 -6.880 l 6.969 -0.534 l 0.508 -0.534 l 0.508 -6.880 l h 7.395 -0.070 m 7.395 -7.344 l 0.121 -7.344 l 0.121 -0.070 l 7.395 -0.070 l h ';
1548 $cb_on = 'q ' . $matrix . ' cm ' . $fill . $radio_color . ' rg ' . $square . ' f ' . $radio_color . ' rg
1549 6.321 -1.352 m 5.669 -2.075 5.070 -2.801 4.525 -3.532 c 3.979 -4.262 3.508 -4.967 3.112 -5.649 c 3.080 -5.706 3.039 -5.779 2.993 -5.868 c 2.858 -6.118 2.638 -6.243 2.334 -6.243 c 2.194 -6.243 2.100 -6.231 2.052 -6.205 c 2.003 -6.180 1.954 -6.118 1.904 -6.020 c 1.787 -5.788 1.688 -5.523 1.604 -5.226 c 1.521 -4.930 1.480 -4.721 1.480 -4.600 c 1.480 -4.535 1.491 -4.484 1.512 -4.447 c 1.535 -4.410 1.579 -4.367 1.647 -4.319 c 1.733 -4.259 1.828 -4.210 1.935 -4.172 c 2.040 -4.134 2.131 -4.115 2.205 -4.115 c 2.267 -4.115 2.341 -4.232 2.429 -4.469 c 2.437 -4.494 2.444 -4.511 2.448 -4.522 c 2.451 -4.531 2.456 -4.546 2.465 -4.568 c 2.546 -4.795 2.614 -4.910 2.668 -4.910 c 2.714 -4.910 2.898 -4.652 3.219 -4.136 c 3.539 -3.620 3.866 -3.136 4.197 -2.683 c 4.426 -2.367 4.633 -2.103 4.816 -1.889 c 4.998 -1.676 5.131 -1.544 5.211 -1.493 c 5.329 -1.426 5.483 -1.368 5.670 -1.319 c 5.856 -1.271 6.066 -1.238 6.296 -1.217 c 6.321 -1.352 l h f Q ';
1550 $cb_off = 'q ' . $matrix . ' cm ' . $fill . $radio_color . ' rg ' . $square . ' f Q ';
1551 }
1552 $this->mpdf->_newobj();
1553 $p = ($this->mpdf->compress) ? gzcompress($cb_on) : $cb_on;
1554 $this->mpdf->_out('<<' . $filter . '/Length ' . strlen($p) . ' /Resources 2 0 R>>');
1555 $this->mpdf->_putstream($p);
1556 $this->mpdf->_out('endobj');
1557
1558 // output appearance stream for check box off (only if not using ZapfDingbats)
1559 if (!$this->formUseZapD) {
1560 $this->mpdf->_newobj();
1561 $p = ($this->mpdf->compress) ? gzcompress($cb_off) : $cb_off;
1562 $this->mpdf->_out('<<' . $filter . '/Length ' . strlen($p) . ' /Resources 2 0 R>>');
1563 $this->mpdf->_putstream($p);
1564 $this->mpdf->_out('endobj');
1565 }
1566 }
1567 return $n;
1568 }
1569
1570 function _putform_ch($form, $hPt)
1571 {
1572 $put_js = 0;
1573 $this->mpdf->_newobj();
1574 $n = $this->mpdf->n;
1575 $this->pdf_acro_array .= $n . ' 0 R ';
1576 $this->forms[$form['n']]['obj'] = $n;
1577
1578 $this->mpdf->_out('<<');
1579 $this->mpdf->_out('/Type /Annot ');
1580 $this->mpdf->_out('/Subtype /Widget');
1581 $this->mpdf->_out('/Rect [ ' . $this->_form_rect($form['x'], $form['y'], $form['w'], $form['h'], $hPt) . ' ]');
1582 $this->mpdf->_out('/F 4');
1583 $this->mpdf->_out('/FT /Ch');
1584 if ($form['Q'])
1585 $this->mpdf->_out('/Q ' . $form['Q'] . '');
1586 $temp = '';
1587 $temp .= '/W ' . $form['BS_W'] . ' ';
1588 $temp .= '/S /' . $form['BS_S'] . ' ';
1589 $this->mpdf->_out("/BS << $temp >>");
1590
1591 $temp = '';
1592 $temp .= '/BC [ ' . $form['BC_C'] . " ] ";
1593 $temp .= '/BG [ ' . $form['BG_C'] . " ] ";
1594 $this->mpdf->_out('/MK << ' . $temp . ' >>');
1595
1596 $this->mpdf->_out('/NM ' . $this->mpdf->_textstring(sprintf('%04u-%04u', $n, (6000 + $form['n']))));
1597 $this->mpdf->_out('/M ' . $this->mpdf->_textstring('D:' . date('YmdHis')));
1598
1599 $this->mpdf->_out('/T ' . $this->mpdf->_textstring($form['T']));
1600 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$form['style']['font']]['i'] . ' ' . $form['style']['fontsize'] . ' Tf ' . $form['style']['fontcolor'] . ')');
1601
1602 $opt = '';
1603 for ($i = 0; $i < count($form['OPT']['VAL']); $i++) {
1604 $opt .= '[ ' . $this->mpdf->_textstring($form['OPT']['VAL'][$i]) . ' ' . $this->mpdf->_textstring($form['OPT']['OPT'][$i]) . ' ] ';
1605 }
1606 $this->mpdf->_out('/Opt [ ' . $opt . ']');
1607
1608 // selected
1609 $selectItem = false;
1610 $selectIndex = false;
1611 foreach ($form['OPT']['SEL'] as $selectKey => $selectVal) {
1612 $selectName = $this->mpdf->_textstring($form['OPT']['VAL'][$selectVal]);
1613 $selectItem .= ' ' . $selectName . ' ';
1614 $selectIndex .= ' ' . $selectVal . ' ';
1615 }
1616 if ($selectItem) {
1617 if (count($form['OPT']['SEL']) < 2) {
1618 $this->mpdf->_out('/V ' . $selectItem . ' ');
1619 $this->mpdf->_out('/DV ' . $selectItem . ' ');
1620 } else {
1621 $this->mpdf->_out('/V [' . $selectItem . '] ');
1622 $this->mpdf->_out('/DV [' . $selectItem . '] ');
1623 }
1624 $this->mpdf->_out('/I [' . $selectIndex . '] ');
1625 }
1626
1627 if (is_array($form['FF']) && count($form['FF']) > 0) {
1628 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']) . ' ');
1629 }
1630 // Javascript
1631 if (isset($this->array_form_choice_js[$form['T']])) {
1632 $this->mpdf->_out("/AA << /V " . ($this->mpdf->n + 1) . " 0 R >>");
1633 $put_js = 1;
1634 }
1635
1636 $this->mpdf->_out('>>');
1637 $this->mpdf->_out('endobj');
1638 // obj + 1
1639 if ($put_js == 1) {
1640 $this->mpdf->_set_object_javascript($this->array_form_choice_js[$form['T']]['js']);
1641 unset($this->array_form_choice_js[$form['T']]);
1642 $put_js = NULL;
1643 }
1644
1645 return $n;
1646 }
1647
1648 function _putform_tx($form, $hPt)
1649 {
1650 $put_js = 0;
1651 $this->mpdf->_newobj();
1652 $n = $this->mpdf->n;
1653 $this->pdf_acro_array .= $n . ' 0 R ';
1654 $this->forms[$form['n']]['obj'] = $n;
1655
1656 $this->mpdf->_out('<<');
1657 $this->mpdf->_out('/Type /Annot ');
1658 $this->mpdf->_out('/Subtype /Widget ');
1659
1660 $this->mpdf->_out('/Rect [ ' . $this->_form_rect($form['x'], $form['y'], $form['w'], $form['h'], $hPt) . ' ] ');
1661 $form['hidden'] ? $this->mpdf->_out('/F 2 ') : $this->mpdf->_out('/F 4 ');
1662 $this->mpdf->_out('/FT /Tx ');
1663
1664 $this->mpdf->_out('/H /N ');
1665 $this->mpdf->_out('/R 0 ');
1666
1667 if (is_array($form['FF']) && count($form['FF']) > 0) {
1668 $this->mpdf->_out('/Ff ' . $this->_setflag($form['FF']) . ' ');
1669 }
1670 if (isset($form['maxlen']) && $form['maxlen'] > 0) {
1671 $this->mpdf->_out('/MaxLen ' . $form['maxlen']);
1672 }
1673
1674 $temp = '';
1675 $temp .= '/W ' . $form['BS_W'] . ' ';
1676 $temp .= '/S /' . $form['BS_S'] . ' ';
1677 $this->mpdf->_out("/BS << $temp >>");
1678
1679 $temp = '';
1680 $temp .= '/BC [ ' . $form['BC_C'] . " ] ";
1681 $temp .= '/BG [ ' . $form['BG_C'] . " ] ";
1682 $this->mpdf->_out('/MK <<' . $temp . ' >>');
1683
1684 $this->mpdf->_out('/T ' . $this->mpdf->_textstring($form['T']));
1685 $this->mpdf->_out('/TU ' . $this->mpdf->_textstring($form['TU']));
1686 if ($form['V'] || $form['V'] === '0')
1687 $this->mpdf->_out('/V ' . $this->mpdf->_textstring($form['V']));
1688 $this->mpdf->_out('/DV ' . $this->mpdf->_textstring($form['DV']));
1689 $this->mpdf->_out('/DA (/F' . $this->mpdf->fonts[$form['style']['font']]['i'] . ' ' . $form['style']['fontsize'] . ' Tf ' . $form['style']['fontcolor'] . ')');
1690 if ($form['Q'])
1691 $this->mpdf->_out('/Q ' . $form['Q'] . '');
1692
1693 $this->mpdf->_out('/NM ' . $this->mpdf->_textstring(sprintf('%04u-%04u', $n, (5000 + $form['n']))));
1694 $this->mpdf->_out('/M ' . $this->mpdf->_textstring('D:' . date('YmdHis')));
1695
1696
1697 if (isset($this->array_form_text_js[$form['T']])) {
1698 $put_js = 1;
1699 $cc = 0;
1700 $js_str = '';
1701
1702 if (isset($this->array_form_text_js[$form['T']]['F'])) {
1703 $cc++;
1704 $js_str .= '/F ' . ($cc + $this->mpdf->n) . ' 0 R ';
1705 }
1706 if (isset($this->array_form_text_js[$form['T']]['K'])) {
1707 $cc++;
1708 $js_str .= '/K ' . ($cc + $this->mpdf->n) . ' 0 R ';
1709 }
1710 if (isset($this->array_form_text_js[$form['T']]['V'])) {
1711 $cc++;
1712 $js_str .= '/V ' . ($cc + $this->mpdf->n) . ' 0 R ';
1713 }
1714 if (isset($this->array_form_text_js[$form['T']]['C'])) {
1715 $cc++;
1716 $js_str .= '/C ' . ($cc + $this->mpdf->n) . ' 0 R ';
1717 $this->pdf_array_co .= $this->mpdf->n . ' 0 R ';
1718 }
1719 $this->mpdf->_out('/AA << ' . $js_str . ' >>');
1720 }
1721
1722 $this->mpdf->_out('>>');
1723 $this->mpdf->_out('endobj');
1724
1725 if ($put_js == 1) {
1726 if (isset($this->array_form_text_js[$form['T']]['F'])) {
1727 $this->mpdf->_set_object_javascript($this->array_form_text_js[$form['T']]['F']['js']);
1728 unset($this->array_form_text_js[$form['T']]['F']);
1729 }
1730 if (isset($this->array_form_text_js[$form['T']]['K'])) {
1731 $this->mpdf->_set_object_javascript($this->array_form_text_js[$form['T']]['K']['js']);
1732 unset($this->array_form_text_js[$form['T']]['K']);
1733 }
1734 if (isset($this->array_form_text_js[$form['T']]['V'])) {
1735 $this->mpdf->_set_object_javascript($this->array_form_text_js[$form['T']]['V']['js']);
1736 unset($this->array_form_text_js[$form['T']]['V']);
1737 }
1738 if (isset($this->array_form_text_js[$form['T']]['C'])) {
1739 $this->mpdf->_set_object_javascript($this->array_form_text_js[$form['T']]['C']['js']);
1740 unset($this->array_form_text_js[$form['T']]['C']);
1741 }
1742 }
1743 return $n;
1744 }
1745
1746 }
1747