1.word转pdf 需要用到 LibreOffice 便携版 如果是linux可以去官网查看安装命令
$retval = 1;
// exec() might be disabled url需要填写相对地址
$cmd = "D:\LibreOfficePortable/LibreOfficeWriterPortable.exe --headless --convert-to pdf D:\phpstudy_pro\WWW\ReadWord\upload\\$name.docx --outdir D:\phpstudy_pro\WWW\ReadWord\upload\\";
if (function_exists('exec')){
@exec($cmd, $output, $retval);
}
// Did it work?
if ($retval > 0){
exit('process_failed');
}else{
sleep(5);
header('location:./phpword.php?name='.$name);
}
2.pdf 读取
1.需要安装composer
2.在项目下面 composer require smalot/pdfparser 安装扩展 安装成功你会看到 vendor文件夹
include 'vendor/autoload.php';
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile("./upload/$name.pdf");
$text = $pdf->getText();
//读取出来的内容是字符串
// Retrieve all pages from the pdf file.
$pages = $pdf->getPages();
// Loop over each page to extract text.
foreach ($pages as $page) {
echo $text = $page->getText();
// $text = explode("\n",$text);
// echo '
';
// print_r($text);
// foreach($text as $kk => $vv){
// echo $vv.'
';
// }
}
标签:word,name,--,text,upload,pdf,php,page
来源: https://www.cnblogs.com/LF-place/p/13569412.html