public function getContent($file)
    {
        $this->fileInfo = GeneralUtility::makeInstance(Fileinfo::class);
        $this->fileInfo->setFile($file);

        // get PDF informations
        if (!$pdfInfo = $this->getPdfInfo($file)) {
            return false;
        }

        // proceed only of there are any pages found
        if ((int)$pdfInfo['pages'] && $this->isAppArraySet) {
            // create the tempfile which will contain the content
            $tempFileName = GeneralUtility::tempnam('pdf_files-Indexer');

            // Delete if exists, just to be safe.
            @unlink($tempFileName);

            // generate and execute the pdftotext commandline tool
            $fileEscaped = CommandUtility::escapeShellArgument($file);
            $cmd = "{$this->app['pdftotext']} -enc UTF-8 -q $fileEscaped $tempFileName";

            CommandUtility::exec($cmd);

            // check if the tempFile was successfully created
            if (@is_file($tempFileName)) {
                $content = GeneralUtility::getUrl($tempFileName);
                unlink($tempFileName);
            } else {
                $errorMessage = 'Content for file ' . $file . ' could not be extracted. Maybe it is encrypted?';
                $this->pObj->logger->warning($errorMessage);
                $this->addError($errorMessage);

                // return empty string if no content was found
                $content = '';
            }

            return $this->removeEndJunk($content);
        } else {
            return false;
        }
    }
public function getContent($file)
    {
        $this->fileInfo = GeneralUtility::makeInstance(Fileinfo::class);
        $this->fileInfo->setFile($file);

        // get PDF informations
        if (!$pdfInfo = $this->getPdfInfo($file)) {
            return false;
        }

        // proceed only of there are any pages found
        if ((int)$pdfInfo['pages'] && $this->isAppArraySet) {
            // create the tempfile which will contain the content
            $tempFileName = GeneralUtility::tempnam('pdf_files-Indexer');

            // Delete if exists, just to be safe.
            @unlink($tempFileName);

            // generate and execute the pdftotext commandline tool
            $fileEscaped = CommandUtility::escapeShellArgument($file);
            $cmd = "{$this->app['pdftotext']} -enc UTF-8 -q $fileEscaped $tempFileName";

            CommandUtility::exec($cmd);

            // check if the tempFile was successfully created
            if (@is_file($tempFileName)) {
                $content = GeneralUtility::getUrl($tempFileName);
                unlink($tempFileName);
            } else {
                $errorMessage = 'Content for file ' . $file . ' could not be extracted. Maybe it is encrypted?';
                $this->pObj->logger->warning($errorMessage);
                $this->addError($errorMessage);

                // return empty string if no content was found
                $content = '';
            }

            return $this->removeEndJunk($content);
        } else {
            return false;
        }
    }
public function getContent ( $ file ) { $ this -> fileInfo = GeneralUtility :: makeInstance ( Fileinfo :: class ) ; $ this -> fileInfo -> setFile ( $ file ) ; // get PDF informations if ( ! $ pdfInfo = $ this -> getPdfInfo ( $ file ) ) { return false ; } // proceed only of there are any pages found if ( ( int ) $ pdfInfo [ 'pages' ] && $ this -> isAppArraySet ) { // create the tempfile which will contain the content $ tempFileName = GeneralUtility :: tempnam ( 'pdf_files-Indexer' ) ; // Delete if exists, just to be safe. @ unlink ( $ tempFileName ) ; // generate and execute the pdftotext commandline tool $ fileEscaped = CommandUtility :: escapeShellArgument ( $ file ) ; $ cmd = "{$this->app['pdftotext']} -enc UTF-8 -q $fileEscaped $tempFileName" ; CommandUtility :: exec ( $ cmd ) ; // check if the tempFile was successfully created if ( @ is_file ( $ tempFileName ) ) { $ content = GeneralUtility :: getUrl ( $ tempFileName ) ; unlink ( $ tempFileName ) ; } else { $ errorMessage = 'Content for file ' . $ file . ' could not be extracted. Maybe it is encrypted?' ; $ this -> pObj -> logger -> warning ( $ errorMessage ) ; $ this -> addError ( $ errorMessage ) ; // return empty string if no content was found $ content = '' ; } return $ this -> removeEndJunk ( $ content ) ; } else { return false ; } }
get Content of PDF file
@param string $file
@return string The extracted content of the file
get Content of PDF file