note 92770 deleted from ref.pdf by googleguy

From: Date: Tue, 22 Oct 2013 11:15:28 +0000
Subject: note 92770 deleted from ref.pdf by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197043@lists.php.net to get a copy of this message
Note Submitter: Janvarev from GMail.com ---- Hi, there is some more fix from luc pdf2text function. It really works at my tasks. Two fixes: 1) Different platforms set different characters after start "stream" text, for example: "stream\n", "stream\r", "stream\r\n". So, we detect it first. 2) Some non-text blocks are detected as text, so we added a function "FilterNonText". <?php function handleV2($data){ // try detecting \n, \r or \r\n variation $tmp = strpos($data, "stream"); $end_stream_delimiter = substr($data, $tmp+6, 2); if($end_stream_delimiter != "\r\n") { $end_stream_delimiter = substr($end_stream_delimiter, 0, 1); } //echo bin2hex($end_stream_delimiter); // - debug information // grab objects and then grab their contents (chunks) $a_obj = getDataArray($data,"obj","endobj"); foreach($a_obj as $obj){ $a_filter = getDataArray($obj,"<<",">>"); if (is_array($a_filter)){ $j++; $a_chunks[$j]["filter"] = $a_filter[0]; $a_data = getDataArray($obj,"stream". $end_stream_delimiter,"endstream"); if (is_array($a_data)){ $a_chunks[$j]["data"] = substr($a_data[0], strlen("stream".$end_stream_delimiter), strlen($a_data[0])- strlen("stream".$end_stream_delimiter)-strlen("endstream")); } } } // decode the chunks foreach($a_chunks as $chunk){ // look at each chunk and decide how to decode it - by looking at the contents of the filter $a_filter = split("/",$chunk["filter"]); if ($chunk["data"]!=""){ // look at the filter to find out which encoding has been used if (substr($chunk["filter"],"FlateDecode")!==false){ $data =@ gzuncompress($chunk["data"]); if (trim($data)!=""){ // CHANGED HERE, before: $result_data .= ps2txt($data); $result_data .= FilterNonText(PS2Text_New($data)); } else { //$result_data .= "x"; } } } } return $result_data; } function FilterNonText($data) { for($i=1;$i<9;$i++) { if(strpos($data, chr($i)) !== false) { return ""; // not text, something strange } } return $data; } ?> Warning: this is only a patch to "luc at phpt dot org" code. You must use his solution first, then replace function with this patch.

« previous php.notes (#197043) next »