admin管理员组文章数量:1605159
PHP 安装COM组件
注意:php版本>5.3.15,需要保证ext文件夹下有php_com_dotnet.dll 并在php.ini中加入
extension=php_com_dotnet.dll
php.ini中搜索并去除com.allow_dcom = true前面的‘;’
com.allow_dcom = true
注意:此组件需要服务器内安装Office组件
office2016官方下载免费完整版_office2016正式版-系统之家-系统下载
/**
* @package word文档转pdf
* @param string $wordPath word原文件路径
* @param string $outPath pdf输出路径
* @return string
*/
function word_turn_pdf($wordPath, $outPath)
{
// 原文件不存在则返回错误
if(!file_exists($wordPath))
{
return 'word原文件不存在';
}
// 输出目录不存在则创建目录
if(!file_exists($tmpPath = rtrim($outPath, basename($outPath))))
{
mkdir($tmpPath, 0777, true);
}
$filenamedoc = $wordPath;
$filenamepdf = $outPath;
// 删除已有同名文件
if(file_exists($filenamepdf))
{
unlink($filenamepdf);
}
// 执行转换操作
$word = new COM("word.Application") or die("Could not initialise Object");
$word->Documents->Open($filenamedoc);
$word->ActiveDocument->ExportAsFixedFormat($filenamepdf, 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
$word->Quit(false);
unset($word);
// 在页面中显示生成的pdf
// header('Content-type: application/pdf');
// header('filename='.$filenamepdf);
// readfile($filenamepdf);
return $outPath;
}
版权声明:本文标题:PHP将Word转PDF文件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1728480177a1160022.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论