Beispiel #1
0
 /**
  * @brief check pdf for metadata
  *
  * @param string $path path to pdf
  * @param arrayref $meta reference to array of metadata
  */
 public static function pdf($path, &$meta)
 {
     if (\OC_Util::runningOnWindows()) {
         /* not supported when running on Windows due to use of exec() */
         return;
     }
     /* first, try to get metadata through ISBN */
     $command = ['pdftotext -l 10 "', '" -'];
     $output = array();
     exec($command[0] . $path . $command[1], $output);
     if (!($output && ($isbn = Isbn::scan($output)) && Isbn::get($isbn, $meta))) {
         /* No ISBN, try PDF metadata */
         $output = array();
         $command = ["pdfinfo '", "'|grep -we '^\\(Title\\|Author\\|Subject\\|Keywords\\|CreationDate\\|ModDate\\)'"];
         exec($command[0] . $path . $command[1], $output);
         foreach ($output as $data) {
             list($key, $value) = explode(':', $data, 2);
             $value = trim($value);
         }
         if (isset($value) && !($value == '')) {
             switch ($key) {
                 case 'Title':
                     $meta['title'] = $value;
                     break;
                 case 'Author':
                     $meta['author'] = $value;
                     break;
                 case 'Subject':
                 case 'Keywords':
                     $meta['subjects'] .= $value;
                     break;
                 case 'CreationDate':
                 case 'ModDate':
                     $meta['date'] = strtotime($value);
                     break;
             }
         }
     }
 }