form.php 64 KB

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