Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Wednesday, April 6, 2011

Convert PDF to TEXT with PHP and Linux

To install pdftotext, use: apt-get install xpdf
$file     = $directory.'/'.$filename;
$fileinfo = pathinfo($filename);
$content  = "";

// pdt to text
if($fileinfo['extension'] == 'pdf')
{
   $outpath = preg_replace("/\.pdf$/", "", $file).".txt";
   system("pdftotext -enc UTF-8 ".escapeshellcmd($file), $ret);
   if($ret == 0) {
      $content = file_get_contents($outpath);
      unlink($outpath);
   }
}