Jump to content

PDFTOTEXT


Guest nishac

Recommended Posts

I am a starter only.But my firm has assigned me a work.I have to read the contents of files ie.text and pdf files.From text files we can easily read.But from pdf we cannot.So a plugin called xpdf is available.In that pdftotext command converts pdf files to text and make it readable.What makes me wonder is that it worked perfectly offline.In my local host.But when am uploading it online the same code is not working.I changed the folder file permissions everything.But in vain.So i have regarding how to give the pdftotext path correctly which can convert my pdf file to text.Am herby attaching the code also.


define('CONVERT_PATH', str_replace('\\', '/', dirname(__FILE__)));
function convert_pdf2text($data, $path2xpdf = null)
{
  if (!$path2xpdf) { 
        return '';
    }
    $tmpname = time();

      umask(0755);
      $fp = @fopen(CONVERT_PATH.'/'.$tmpname.'.pdf', "w+");
   
if (!$fp) {
        return '';
    } else {
        fwrite($fp, $data);
fclose($fp);
        chmod(CONVERT_PATH.'/'.$tmpname.'.pdf', 0755);
       
        exec($path2xpdf.' '.CONVERT_PATH.'/'.$tmpname.'.pdf '.CONVERT_PATH.'/'.$tmpname.'.txt');
       
        if (file_exists(CONVERT_PATH.'/'.$tmpname.'.txt')) {
            chmod(CONVERT_PATH.'/'.$tmpname.'.txt', 0755);
            $text = @file_get_contents(CONVERT_PATH.'/'.$tmpname.'.txt');
            @unlink(CONVERT_PATH.'/'.$tmpname.'.pdf');
            @unlink(CONVERT_PATH.'/'.$tmpname.'.txt');
            clearstatcache();
           
return $text;
        } else {
            @unlink(CONVERT_PATH.'/'.$tmpname.'.pdf');
            @unlink(CONVERT_PATH.'/'.$tmpname.'.txt');
            clearstatcache();
            return '';
        } 
    }
}

thanking u
Link to comment
https://forums.phpfreaks.com/topic/30724-pdftotext/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.