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);
   }
}

1 comment:

  1. I'm not a developer, i always use this free online pdf to text converter to convert pdf to text online.

    ReplyDelete