0

I am trying to make a webpage to convert a pdf to text file using xpdf.
Below is the php code to do it on windows using xampp.

<?php
$filename = array();
$filename ="/Applications/XAMPP/xamppfiles/htdocs/abc/test.pdf";//Path of the file

//while ($filename = readdir($dir)) {
if (eregi("\.pdf",$filename)){

$content  = shell_exec('/usr/local/bin/pdftotext -raw'.' '.$filename.' -');//$content stores the content of the pdf as string



$read =basename($filename,".pdf");//extracting file name 
$testfile = "$read.txt";//changing extension of filename
$file     = fopen("/Applications/XAMPP/xamppfiles/htdocs/".$testfile,"w");// creates new file of the same name in at the given location
fwrite($file, $content);//writes content to file
if (filesize($testfile)==0){} //checks if file null
else{
$text = fread($file,filesize($testfile));
fclose($file);
echo "</br>"; echo "</br>";
}
}?>

Now i want to run it on linux VPS.
I have a Cent OS VPS with SSH access. I have installed zpanel, xpdf (using yum install xpdf).
Now i want, when i open this URL "www.website.com/convert.php" in browser, the test.pdf file in public_html folder should convert to test.txt in same folder.

So, what code should i write in convert.php?

  • What have you tried? Was there an error, if so, what is it? What was the result?> What was the expected result? – Ohgodwhy Oct 04 '14 at 23:06
  • i tried the following changes $filename = "/var/zpanel/hostdata/zadmin/public_html/test.pdf";//path of the file $content = shell_exec('pdftotext -raw'.' '.$filename.' -'); $file = fopen("/var/zpanel/hostdata/zadmin/public_html/".$testfile,"w"); – Ankush Garg Oct 04 '14 at 23:11
  • the expected result is to get test.txt in same directory. But nothing happens when i run it. – Ankush Garg Oct 04 '14 at 23:15

0 Answers0