PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.9.0
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.9.0
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 1.9.0, at mpdf/classes/mpdfform.php

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