> * endobj */ Class PDFMetaData{ private $keys=array( 'Title', 'Author', 'Subject', 'Keywords' // 'Creator', // 'Producer', // 'ModDate', ); // regex for parsing PDF meta var $objects='/<<(.*)>>/'; var $items='/\/(?P[A-Z][A-Za-z]*)\((?P[^)\/]*)\)/'; /** * @desc Take a file path or URL, and send it for processing * @return Results as array from extractMeta * @param File URL or local path * @author Leo Brown * */ function getMeta($file){ if($data = @file_get_contents($file)){ return $this->extractMeta($data); } } /** * @desc Take a PDF or PDF dictionary as a binary string and return the meta elements * @param $data Binary string of PDF or PDF dictionary * @return Array PDF Metadata * @author Leo Brown * */ function extractMeta($data){ $meta = array(); // objects $objects=array(); preg_match_all($this->objects,$data,$objects); $objects=end($objects); // iterate matches foreach($objects as $object){ $items=array(); preg_match_all($this->items,$data,$items); foreach($this->keys as $key){ if($index = array_search($key, $items['key'])){ $meta[$key]=$items['value'][$index]; } // if we have all keys, we can stop parsing if(count($this->keys)==count($meta)) break 2; } } return $meta; } } ?>