【发布时间】:2017-06-03 17:52:22
【问题描述】:
我正在尝试使用 COM 类将 doc 文件转换为 pdf,但它会抛出错误
致命错误:找不到类 COM
我已经尝试在我的计算机上安装的所有 php.ini 文件中取消注释所需的扩展名。
[COM_DOT_NET] extension=php_com_dotnet.dll
我还更改了扩展的目录路径
在窗户上: extension_dir="c:/wamp64/bin/php/php5.6.25/ext/"
以下是我的代码: 1. 我已经将 apache office 保存在 PHP 文件夹中。 2.在win7上使用WAMP 3. 每次更新 php.ini 文件时,我都会刷新本地服务器
<?php
set_time_limit(0);
function MakePropertyValue($name,$value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function word2pdf($doc_url, $output_url){
//Invoke the OpenOffice.org service manager
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
//Set the application to remain hidden to avoid flashing the document onscreen
$args = array(MakePropertyValue("Hidden",true,$osm));
//Launch the desktop
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
//Load the .doc file, and pass in the "Hidden" property from above
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
//Set up the arguments for the PDF output
$export_args = array(MakePropertyValue("FilterName","writer_pdf_Export",$osm));
//print_r($export_args);
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
$output_dir = "C:/wamp/www/";
$doc_file = "C:/wamp/www/reportdoc.docx";
$pdf_file = "reportpdf.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>
我可能已经尝试了所有解决方案,但仍然没有任何帮助。
【问题讨论】: