xpdfを使用してpdfをテキストファイルに変換するWebページを作成しようとしています。
以下は、xampp を使用して Windows で実行するための php コードです。
<?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>";
}
}?>
今、Linux VPSで実行したいです。
SSH アクセスを備えた Cent OS VPS があります。zpanel、xpdf をインストールしました (yum install xpdf を使用)。
ここで、この URL "www.website.com/convert.php" をブラウザーで開くと、public_html フォルダー内の test.pdf ファイルが同じフォルダー内の test.txt に変換されます。
では、convert.php にはどのようなコードを記述すればよいでしょうか。