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