PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/pdf/output.pdflib.1.6.class.php

http://simpleinvoices.googlecode.com/
PHP | 225 lines | 180 code | 39 blank | 6 comment | 8 complexity | 86e59f01c9c5d89ba9f0bf15eec65ec9 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0, LGPL-3.0
  1. <?php
  2. // $Header: /cvsroot/html2ps/output.pdflib.1.6.class.php,v 1.2 2006/11/11 13:43:53 Konstantin Exp $
  3. require_once(HTML2PS_DIR.'output.pdflib.class.php');
  4. class PDFLIBForm {
  5. var $_name;
  6. function PDFLIBForm($name /*, $submit_action, $reset_action */) {
  7. $this->_name = $name;
  8. }
  9. function name() {
  10. return $this->_name;
  11. }
  12. }
  13. class OutputDriverPdflib16 extends OutputDriverPdflib {
  14. function field_multiline_text($x, $y, $w, $h, $value, $name) {
  15. $font = $this->_control_font();
  16. pdf_create_field($this->pdf,
  17. $x, $y, $x + $w, $y - $h,
  18. $this->_fqn($name),
  19. "textfield",
  20. sprintf("currentvalue {%s} defaultvalue {%s} font {%s} fontsize {auto} multiline {true}",
  21. $value,
  22. $value,
  23. $font));
  24. }
  25. function field_text($x, $y, $w, $h, $value, $name) {
  26. $font = $this->_control_font();
  27. pdf_create_field($this->pdf,
  28. $x, $y, $x + $w, $y - $h,
  29. $this->_fqn($name),
  30. "textfield",
  31. sprintf("currentvalue {%s} defaultvalue {%s} font {%s} fontsize {auto}",
  32. $value,
  33. $value,
  34. $font));
  35. }
  36. function field_password($x, $y, $w, $h, $value, $name) {
  37. $font = $this->_control_font();
  38. pdf_create_field($this->pdf,
  39. $x, $y, $x + $w, $y - $h,
  40. $this->_fqn($name),
  41. "textfield",
  42. sprintf("currentvalue {%s} font {%s} fontsize {auto} password {true}", $value, $font));
  43. }
  44. function field_pushbutton($x, $y, $w, $h) {
  45. $font = $this->_control_font();
  46. pdf_create_field($this->pdf,
  47. $x, $y, $x + $w, $y - $h,
  48. $this->_fqn(sprintf("___Button%s",md5(time().rand()))),
  49. "pushbutton",
  50. sprintf("font {%s} fontsize {auto} caption {%s}",
  51. $font,
  52. " "));
  53. }
  54. function field_pushbuttonimage($x, $y, $w, $h, $field_name, $value, $actionURL) {
  55. $font = $this->_control_font();
  56. $action = pdf_create_action($this->pdf,
  57. "SubmitForm",
  58. sprintf("exportmethod {html} url=%s", $actionURL));
  59. pdf_create_field($this->pdf,
  60. $x, $y, $x + $w, $y - $h,
  61. $this->_fqn($field_name),
  62. "pushbutton",
  63. sprintf("action {activate %s} font {%s} fontsize {auto} caption {%s}",
  64. $action,
  65. $font,
  66. " "));
  67. }
  68. function field_pushbuttonreset($x, $y, $w, $h) {
  69. $font = $this->_control_font();
  70. $action = pdf_create_action($this->pdf,
  71. "ResetForm",
  72. sprintf(""));
  73. pdf_create_field($this->pdf,
  74. $x, $y, $x + $w, $y - $h,
  75. $this->_fqn(sprintf("___ResetButton%d",$action)),
  76. "pushbutton",
  77. sprintf("action {activate %s} font {%s} fontsize {auto} caption {%s}",
  78. $action,
  79. $font,
  80. " "));
  81. }
  82. function field_pushbuttonsubmit($x, $y, $w, $h, $field_name, $value, $actionURL) {
  83. $font = $this->_control_font();
  84. $action = pdf_create_action($this->pdf,
  85. "SubmitForm",
  86. sprintf("exportmethod {html} url=%s", $actionURL));
  87. pdf_create_field($this->pdf,
  88. $x, $y, $x + $w, $y - $h,
  89. $this->_fqn($field_name),
  90. "pushbutton",
  91. sprintf("action {activate %s} font {%s} fontsize {auto} caption {%s}",
  92. $action,
  93. $font,
  94. " "));
  95. }
  96. function field_checkbox($x, $y, $w, $h, $name, $value, $checked) {
  97. pdf_create_field($this->pdf,
  98. $x, $y, $x + $w, $y - $h,
  99. $this->_fqn($name),
  100. "checkbox",
  101. sprintf("buttonstyle {cross} currentvalue {%s} defaultvalue {%s} itemname {%s}",
  102. $checked ? $value : "Off",
  103. $checked ? $value : "Off",
  104. $value));
  105. }
  106. function field_radio($x, $y, $w, $h, $groupname, $value, $checked) {
  107. $fqgn = $this->_fqn($groupname, true);
  108. if (!isset($this->_radiogroups[$fqgn])) {
  109. $this->_radiogroups[$fqgn] = pdf_create_fieldgroup($this->pdf, $fqgn, "fieldtype=radiobutton");
  110. };
  111. pdf_create_field($this->pdf,
  112. $x, $y, $x + $w, $y - $h,
  113. sprintf("%s.%s",$fqgn,$value),
  114. "radiobutton",
  115. sprintf("buttonstyle {circle} currentvalue {%s} defaultvalue {%s} itemname {%s}",
  116. $checked ? $value : "Off",
  117. $checked ? $value : "Off",
  118. $value));
  119. }
  120. function field_select($x, $y, $w, $h, $name, $value, $options) {
  121. $items_str = "";
  122. $text_str = "";
  123. foreach ($options as $option) {
  124. $items_str .= sprintf("%s ",$option[0]);
  125. $text_str .= sprintf("%s ",$option[1]);
  126. };
  127. $font = $this->_control_font();
  128. pdf_create_field($this->pdf,
  129. $x, $y, $x + $w, $y - $h,
  130. $this->_fqn($name),
  131. "combobox",
  132. sprintf("currentvalue {%s} defaultvalue {%s} font {%s} fontsize {auto} itemnamelist {%s} itemtextlist {%s}",
  133. $value,
  134. $value,
  135. $font,
  136. $items_str,
  137. $text_str));
  138. }
  139. function new_form($name) {
  140. $this->_forms[] = new PDFLIBForm($name);
  141. pdf_create_fieldgroup($this->pdf, $name, "fieldtype=mixed");
  142. }
  143. /* private routines */
  144. function _control_font() {
  145. return pdf_load_font($this->pdf, "Helvetica", "winansi", "embedding=true subsetting=false");
  146. }
  147. function _lastform() {
  148. if (count($this->_forms) == 0) {
  149. /**
  150. * Handle invalid HTML; if we've met an input control outside the form,
  151. * generate a new form with random name
  152. */
  153. $name = sprintf("AnonymousFormObject_%u", md5(rand().time()));
  154. $this->_forms[] = new PDFLIBForm($name);
  155. pdf_create_fieldgroup($this->pdf, $name, "fieldtype=mixed");
  156. error_log(sprintf("Anonymous form generated with name %s; check your HTML for validity",
  157. $name));
  158. };
  159. return $this->_forms[count($this->_forms)-1];
  160. }
  161. function _valid_name($name) {
  162. if (empty($name)) { return false; };
  163. return true;
  164. }
  165. function _fqn($name, $allowexisting=false) {
  166. if (!$this->_valid_name($name)) {
  167. $name = uniqid("AnonymousFormFieldObject_");
  168. error_log(sprintf("Anonymous field generated with name %s; check your HTML for validity",
  169. $name));
  170. };
  171. $lastform = $this->_lastform();
  172. $fqn = sprintf("%s.%s",
  173. $lastform->name(),
  174. $name);
  175. if (array_search($fqn, $this->_field_names) === FALSE) {
  176. $this->_field_names[] = $fqn;
  177. } elseif (!$allowexisting) {
  178. error_log(sprintf("Interactive form '%s' already contains field named '%s'",
  179. $lastform->name(),
  180. $name));
  181. $fqn .= md5(rand().time());
  182. };
  183. return $fqn;
  184. }
  185. }
  186. ?>