/**
* @description: pdf转word 使用COM组件
* @param pdfPath string 要转换的pdf全路径 E:/1.pdf
* @param outPath string 生成的pdf全路径 E:/2.docx (doc,docx都可以)
* @return:
*/
function xmsb_wordToPdf($pdfPath, $outPath)
{
try {
// 原文件不存在则返回错误
if(!file_exists($pdfPath)) return '原文件不存在';
// 删除已有同名文件
if(file_exists($outPath)) unlink($outPath);
// 执行转换操作
$word = new COM("word.Application") or die("Could not initialise Object");
$word->Documents->Open($pdfPath);
$word->ActiveDocument->SaveAs2($outPath);
$word->Quit(false);
unset($word);
} catch (Exception $e) {
return 0;
}
}
com组件配置:php使用COM组件 office文件(word/excel/ppt)转pdf文件