|
33 | 33 | * V1.0 (03.11.2010) First working release *
|
34 | 34 | *******************************************************************************/
|
35 | 35 |
|
36 |
| -global $FPDM_FILTERS, $FPDM_REGEXPS; //needs explicit global scope, otherwise autoloading will br incomplete. |
| 36 | +global $FPDM_FILTERS, $FPDM_REGEXPS; //needs explicit global scope, otherwise autoloading will be incomplete. |
37 | 37 | $FPDM_FILTERS=array(); //holds all supported filters
|
38 | 38 | $FPDM_REGEXPS= array(
|
| 39 | + //FIX: parse checkbox definition |
| 40 | + "/AS"=>"/\/AS\s+\/(\w+)$/", |
| 41 | + "name"=>"/\/(\w+)/", |
| 42 | + // "/AP_D_SingleLine"=>"/\/D\s+\/(\w+)\s+\d+\s+\d+\s+R\s+\/(\w+)$/", |
| 43 | + //ENDFIX |
39 | 44 | "/Type"=>"/\/Type\s+\/(\w+)$/",
|
40 | 45 | "/Subtype" =>"/^\/Subtype\s+\/(\w+)$/"
|
41 | 46 | );
|
|
66 | 71 |
|
67 | 72 | class FPDM {
|
68 | 73 | //@@@@@@@@@
|
69 |
| - |
| 74 | + var $useCheckboxParser = false; //boolean: allows activation of custom checkbox parser (not available in original FPDM source) |
70 | 75 |
|
71 | 76 | var $pdf_source = ''; //string: full pathname to the input pdf , a form file
|
72 | 77 | var $fdf_source = ''; //string: full pathname to the input fdf , a form data file
|
@@ -867,7 +872,10 @@ function set_field_value($type,$name,$value) {
|
867 | 872 |
|
868 | 873 | $offset_shift=$this->set_field_tooltip($name,$value);
|
869 | 874 |
|
870 |
| - } else {//if(isset($this->value_entries["$name"]["values"]["$type"])) { |
| 875 | + } elseif ($this->useCheckboxParser && isset($this->value_entries["$name"]['infos']['checkbox_state'])) { //FIX: set checkbox value |
| 876 | + $offset_shift=$this->set_field_checkbox($name, $value); |
| 877 | + //ENDFIX |
| 878 | + } else {//if(isset($this->value_entries["$name"]["values"]["$type"])) { |
871 | 879 | // echo $this->value_entries["$name"]["values"]["$type"];
|
872 | 880 | /* $field_value_line=$this->value_entries["$name"]["values"]["$type"];
|
873 | 881 | $field_value_maxlen=$this->value_entries["$name"]["constraints"]["maxlen"];
|
@@ -921,6 +929,60 @@ function set_field_tooltip($name,$value) {
|
921 | 929 | return $offset_shift;
|
922 | 930 | }
|
923 | 931 |
|
| 932 | + //FIX: parse checkbox definition |
| 933 | + /** |
| 934 | + *Changes the checkbox state. |
| 935 | + * |
| 936 | + *@param string $name name of the field to change the state |
| 937 | + *@param string $value the new state to set |
| 938 | + *@return int offset_shift the size variation |
| 939 | + **/ |
| 940 | + public function set_field_checkbox($name, $value) |
| 941 | + { |
| 942 | + //------------------------------------ |
| 943 | + $offset_shift=0; |
| 944 | + $verbose_set=($this->verbose&&($this->verbose_level>1)); |
| 945 | + //Get the line(s) of the misc field values |
| 946 | + if (isset($this->value_entries["$name"])) { |
| 947 | + if (isset($this->value_entries["$name"]["infos"]["checkbox_state_line"]) |
| 948 | + && isset($this->value_entries["$name"]["infos"]["checkbox_no"]) |
| 949 | + && isset($this->value_entries["$name"]["infos"]["checkbox_yes"])) { |
| 950 | + $field_checkbox_line=$this->value_entries["$name"]["infos"]["checkbox_state_line"]; |
| 951 | + if ($field_checkbox_line) { |
| 952 | + if ($verbose_set) { |
| 953 | + echo "<br>Change checkbox of the field $name at line $field_checkbox_line to value [$value]"; |
| 954 | + } |
| 955 | + $state = $this->value_entries["$name"]["infos"]["checkbox_no"]; |
| 956 | + if ($value) { |
| 957 | + $state = $this->value_entries["$name"]["infos"]["checkbox_yes"]; |
| 958 | + } |
| 959 | + $CurLine =$this->pdf_entries[$field_checkbox_line]; |
| 960 | + $OldLen=strlen($CurLine); |
| 961 | + $CurLine = '/AS /'.$state; |
| 962 | + $NewLen=strlen($CurLine); |
| 963 | + $Shift=$NewLen-$OldLen; |
| 964 | + $this->shift=$this->shift+$Shift; |
| 965 | + //Saves |
| 966 | + $this->pdf_entries[$field_checkbox_line]=$CurLine; |
| 967 | + return $Shift; |
| 968 | + // $offset_shift=$this->_set_field_value($field_checkbox_line, $state); |
| 969 | + } else { |
| 970 | + if ($verbose_set) { |
| 971 | + echo "<br>Change checkbox value aborted, parsed checkbox definition incomplete."; |
| 972 | + } |
| 973 | + } |
| 974 | + } else { |
| 975 | + if ($verbose_set) { |
| 976 | + echo "<br>Change checkbox value aborted, the field $name has no checkbox definition."; |
| 977 | + } |
| 978 | + } |
| 979 | + } else { |
| 980 | + $this->Error("set_field_checkbox failed as the field $name does not exist"); |
| 981 | + } |
| 982 | + return $offset_shift; |
| 983 | + } |
| 984 | + //ENDFIX |
| 985 | + |
924 | 986 | /**
|
925 | 987 | *Dumps the line entries
|
926 | 988 | *
|
@@ -1566,7 +1628,14 @@ function parsePDFEntries(&$lines){
|
1566 | 1628 |
|
1567 | 1629 | $Counter=0;
|
1568 | 1630 | $obj=0; //this is an invalid object id, we use it to know if we are into an object
|
1569 |
| - $type=''; |
| 1631 | + //FIX: parse checkbox definition |
| 1632 | + $ap_d_yes=''; |
| 1633 | + $ap_d_no=''; |
| 1634 | + $ap_line=0; |
| 1635 | + $ap_d_line=0; |
| 1636 | + $as=''; |
| 1637 | + //ENDFIX |
| 1638 | + $type=''; |
1570 | 1639 | $subtype='';
|
1571 | 1640 | $name='';
|
1572 | 1641 | $value='';
|
@@ -1642,6 +1711,13 @@ function parsePDFEntries(&$lines){
|
1642 | 1711 |
|
1643 | 1712 | $object=null;
|
1644 | 1713 | $obj=0;
|
| 1714 | + //FIX: parse checkbox definition |
| 1715 | + $ap_d_yes=''; |
| 1716 | + $ap_d_no=''; |
| 1717 | + $ap_line=0; |
| 1718 | + $ap_d_line=0; |
| 1719 | + $as=''; |
| 1720 | + //ENDFIX |
1645 | 1721 | $type='';
|
1646 | 1722 | $subtype='';
|
1647 | 1723 | $name='';
|
@@ -1768,6 +1844,40 @@ function parsePDFEntries(&$lines){
|
1768 | 1844 | //=== DEFINITION ====
|
1769 | 1845 | //preg_match("/^\/Type\s+\/(\w+)$/",$CurLine,$match)
|
1770 | 1846 | $match=array();
|
| 1847 | + //FIX: parse checkbox definition |
| 1848 | + if($this->useCheckboxParser && ('' == $ap_d_yes || '' == $ap_d_no || '' == $as)) { |
| 1849 | + if (!$ap_line && '/AP' == substr($CurLine, 0, 3)) { |
| 1850 | + if ($verbose_parsing) { |
| 1851 | + echo("<br>Found AP Line '<i>$Counter</i>'"); |
| 1852 | + } |
| 1853 | + $ap_line = $Counter; |
| 1854 | + } elseif (!$ap_d_line && '/D' == substr($CurLine, 0, 2)) { |
| 1855 | + if ($verbose_parsing) { |
| 1856 | + echo("<br>Found D Line '<i>$Counter</i>'"); |
| 1857 | + } |
| 1858 | + $ap_d_line = $Counter; |
| 1859 | + } elseif (($ap_line==$Counter-4)&&($ap_d_line==$Counter-2)&&($ap_d_yes=='')&&$this->extract_pdf_definition_value("name", $CurLine, $match)) { |
| 1860 | + $ap_d_yes=$match[1]; |
| 1861 | + if ($verbose_parsing) { |
| 1862 | + echo("<br>Object's checkbox_yes is '<i>$ap_d_yes</i>'"); |
| 1863 | + } |
| 1864 | + $object["infos"]["checkbox_yes"]=$ap_d_yes; |
| 1865 | + } elseif (($ap_line==$Counter-5)&&($ap_d_line==$Counter-3)&&($ap_d_no=='')&&$this->extract_pdf_definition_value("name", $CurLine, $match)) { |
| 1866 | + $ap_d_no=$match[1]; |
| 1867 | + if ($verbose_parsing) { |
| 1868 | + echo("<br>Object's checkbox_no is '<i>$ap_d_no</i>'"); |
| 1869 | + } |
| 1870 | + $object["infos"]["checkbox_no"]=$ap_d_no; |
| 1871 | + } elseif (($as=='')&&$this->extract_pdf_definition_value("/AS", $CurLine, $match)) { |
| 1872 | + $as=$match[1]; |
| 1873 | + if ($verbose_parsing) { |
| 1874 | + echo("<br>Object's AS is '<i>$as</i>'"); |
| 1875 | + } |
| 1876 | + $object["infos"]["checkbox_state"]=$as; |
| 1877 | + $object["infos"]["checkbox_state_line"]=$Counter; |
| 1878 | + } |
| 1879 | + } |
| 1880 | + //ENDFIX |
1771 | 1881 | if(($type=='')||($subtype=='')||($name=="")) {
|
1772 | 1882 |
|
1773 | 1883 | if(($type=='')&&$this->extract_pdf_definition_value("/Type",$CurLine,$match)) {
|
|
0 commit comments