找不到PHP COM类

时间:2017-01-19 06:07:26

标签: php com

我正在尝试使用COM类将doc文件转换为pdf,但它抛出了错误

  

致命错误:未找到类COM

我已尝试在计算机上安装的所有php.ini文件中取消注释所需的扩展名。

  

[COM_DOT_NET]   延长= php_com_dotnet.dll

我还将dir路径更改为扩展名

  

在Windows上:   extension_dir =“c:/wamp64/bin/php/php5.6.25/ext /”

以下是我的代码: 1.我在PHP文件夹中保存了apache office。 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);
?>

我已经尝试了所有解决方案,但仍然没有任何帮助。

1 个答案:

答案 0 :(得分:0)

所以它可以是一堆东西:

  1. 确保您的php_com_dotnet.dll位于php.ini定义的extension_dir中(我知道但仍然没有脑子)。

  2. 尝试将新COM更改为     $ osm = new \ COM(&#34; com.sun.star.ServiceManager&#34;)或死亡(&#34;请确保已安装OpenOffice.org。\ n&#34;); (如果您使用单独的命名空间,这可能会解决问题)。

  3. 在你的php.ini中,尝试设置extension_dir =&#34; ext&#34;如果你正在使用wamp。 (wamp中的扩展名dir通常位于活动的php版本和ext文件夹中)

  4. 保存php文件并重新启动wamp,希望其中一个可以帮到你。