Location: PHPKode > projects > mediaIndex > classes/handler.pdf.php
<?php
/**
 * $Id: handler.pdf.php,v 1.13 2004/11/26 18:31:22 openface Exp $      
 *
 *               _ _        _         _                 
 *  _ __  ___ __| (_)__ _  (_)_ _  __| |_____ _____ _ _ 
 * | '  \/ -_) _` | / _` | | | ' \/ _` / -_) \ / -_) '_|
 * |_|_|_\___\__,_|_\__,_| |_|_||_\__,_\___/_\_\___|_|  
 *                                                     
 *     Standalone Indexer Script for Media Files
 *        jason hines, <hide@address.com>
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
 * General Public License for more details.
 */

/* absolute path to pdftotext binary */
define("_PDFTOTEXT","/usr/bin/pdftotext");

/* pdftext directory */
define("_PDFTEXTPATH",_CACHEPATH."/pdftext");
define("_PDFTEXTURL",_CACHEURL."/pdftext");

/**
 * Group handler class for Adobe PDF documents
 *
 * @version     $Revision: 1.13 $
 * @package     mediaIndexer
 * @subpackage  handlers
 * @author      jason hines, <hide@address.com>
 */

class pdfHandler extends defaultHandler {

    public $iconName = "pdf.gif";

    public function pdfHandler() {
        if (!is_executable(_PDFTOTEXT)) {
            _addMessage("WARNING! ". _PDFTEXT . " not found. Is PdfToText installed?");
        }
    }

    public function printMedia(file $file) {
      $ptname = $file->hash . ".txt";
      if (!file_exists(_PDFTEXTPATH . "/" . $ptname)) {
          if (!is_writable(_PDFTEXTPATH)) {
              mkdir(_PDFTEXTPATH);
          }
          exec(_PDFTOTEXT . " -layout "._MEDIAPATH.escapeshellarg($file->path)." "._PDFTEXTPATH."/".$ptname,$out,$ret);
          if ($ret != 0) throw new Exception("Unable to generate text from document.");
      }
      echo "<pre>";
      echo _parseText(file_get_contents(_PDFTEXTPATH."/".$ptname));
      echo "</pre>";
    }

}

?>
Return current item: mediaIndex