本帖最后由 liuche 于 2023-3-28 11:48 编辑
XPDF工具安装原文链接:https://blog.csdn.net/plusboss/article/details/116083617
主要是尝试一下发帖子 开发中摘了一段代码
功能很简单,就是利用XPDF工具把文件夹下的PDF文件遍历读取然后将pdf内容在写入文本文件中
需要先安装XPDF工具
各位大佬莫嫌弃~~~~
[Asm] 纯文本查看 复制代码 <?php
#### config ####
$filePath = 'E:\test\test';// 读取文件路径
$xpdfPath = 'D:\xpdf';//XPDF工具安装路径
#### config ####
$filePath = toUtf8($filePath);
$filePath = str_replace('\\',"/", $filePath)."/";
$files = scandir($filePath);
if(empty($files))die("no file");
$pdf_files = array();
foreach($files as $v)
{
if(substr($v,-3) == 'pdf')
$pdf_files[] = toUtf8($v);
}
if(empty($pdf_files))die("no file");
$xpdfPath = str_replace('\\',"/", $xpdfPath)."/";
foreach($pdf_files as $v)
{
$filename = $filePath . $v;
$content = shell_exec ($xpdfPath.'pdftotext '.$filename .' -');
$txtname = substr($filename,0,-4).".txt";
file_put_contents($txtname,$content);
}
function toUtf8($str)
{
$encode = mb_detect_encoding($str,'UTF-8');
if($encode!='UTF-8')
{
$str=@mb_convert_encoding($str,'UTF-8',$encode);
}
return $str;
} |