note 92770 added to ref.pdf

From: Date: Sat, 08 Aug 2009 09:38:26 +0000
Subject: note 92770 added to ref.pdf
Groups: php.notes 
Request: Send a blank email to php-notes+get-159209@lists.php.net to get a copy of this message
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. ---- Server IP: 83.137.20.135 Probable Submitter: 95.221.170.233 ---- Manual Page -- http://www.php.net/manual/en/ref.pdf.php Edit -- https://master.php.net/note/edit/92770 Del: integrated -- https://master.php.net/note/delete/92770/integrated Del: useless -- https://master.php.net/note/delete/92770/useless Del: bad code -- https://master.php.net/note/delete/92770/bad+code Del: spam -- https://master.php.net/note/delete/92770/spam Del: non-english -- https://master.php.net/note/delete/92770/non-english Del: in docs -- https://master.php.net/note/delete/92770/in+docs Del: other reasons-- https://master.php.net/note/delete/92770 Reject -- https://master.php.net/note/reject/92770 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159209) next »