将office文件转换为pdf的方法有以下几种:
使用OpenOffice提供的服务(这种方法相对简单,但转换效果可能不理想)。
使用Office提供的服务(注意:这需要在安装了高版本Office的Windows服务器上进行)。
接下来,我们将重点介绍如何利用Office服务将Office文件转换为PDF。
首先,打开php.ini文件,搜索php_com_dotnet并进行如下配置:
立即学习“PHP免费学习笔记(深入)”;
extension=php_com_dotnet.dll // 移除前面的分号 com.allow_dcom = true // 改为true
完成配置后,重启Apache服务器。









还有以下两个操作:


public function ppt_to_pdf() {
$srcfilename = 'E:/aa.ppt';
$destfilename = 'E:/aa.pdf';
try {
if(!file_exists($srcfilename)){
return;
}
$ppt = new \COM("powerpoint.application") or die("Unable to instantiate Powerpoint");
$presentation = $ppt->Presentations->Open($srcfilename, false, false, false);
$presentation->SaveAs($destfilename,32,1);
$presentation->Close();
$ppt->Quit();
} catch (\Exception $e) {
if (method_exists($ppt, "Quit")){
$ppt->Quit();
}
return;
}
}public function excel_to_pdf() {
$srcfilename = 'E:/aa.xls';
$destfilename = 'E:/aa.pdf';
try {
if(!file_exists($srcfilename)){
return;
}
$excel = new \COM("excel.application") or die("Unable to instantiate excel");
$workbook = $excel->Workbooks->Open($srcfilename, null, false, null, "1", "1", true);
$workbook->ExportAsFixedFormat(0, $destfilename);
$workbook->Close();
$excel->Quit();
} catch (\Exception $e) {
echo ("src:$srcfilename catch exception:" . $e->__toString());
if (method_exists($excel, "Quit")){
$excel->Quit();
}
return;
}
}public function doc_to_pdf() {
$srcfilename = 'E:/aa.doc';
$destfilename = 'E:/aa.pdf';
try {
if(!file_exists($srcfilename)){
return;
}
$word = new \COM("word.application") or die("Can't start Word!");
$word->Visible=0;
$word->Documents->Open($srcfilename, false, false, false, "1", "1", true);
$word->ActiveDocument->final = false;
$word->ActiveDocument->Saved = true;
$word->ActiveDocument->ExportAsFixedFormat(
$destfilename,
17, // wdExportFormatPDF
false, // open file after export
0, // wdExportOptimizeForPrint
3, // wdExportFromTo
1, // begin page
5000, // end page
7, // wdExportDocumentWithMarkup
true, // IncludeDocProps
true, // KeepIRM
1 // WdExportCreateBookmarks
);
$word->ActiveDocument->Close();
$word->Quit();
} catch (\Exception $e) {
if (method_exists($word, "Quit")){
$word->Quit();
}
return;
}
}注:本文参考地址:https://www.php.cn/link/567dbf6a65b57563c28e6311c42cc2d0
以上就是windows环境下 php 将office文件(word/excel/ppt)转化为pdf(转)的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号