【问题标题】:PHP COM class not found未找到 PHP COM 类
【发布时间】: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);
?>

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

【问题讨论】:

    标签: php com


    【解决方案1】:

    所以它可以是一堆东西:

    1. 确保您的 php_com_dotnet.dll 位于 php.ini 定义的 extension_dir 中(我不知道但仍然如此)。

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

    3. 如果您使用 wamp,请在您的 php.ini 中尝试设置 extension_dir="ext"。 (wamp 中的扩展目录通常在激活的 php 版本下和 ext 文件夹中)

    保存 php 文件并重新启动 wamp,希望其中一个可以为您解决问题。

    【讨论】:

      猜你喜欢
      • 2012-08-07
      • 2013-08-16
      • 2013-04-20
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      相关资源
      最近更新 更多