我的操作系统是 Windows XP,我使用的是 IIS 5.1 和 PHP 5.2.9。我正在尝试从我的 PHP 页面调用 PHP 脚本,以便使用 OpenOffice 将 RTF 文档转换为 PDF。当我直接从命令行调用它时,该脚本工作得很好,但是当我从我的 PHP 网页启动时,我没有成功让相同的脚本工作。
当我从我的 PHP 页面调用脚本时,页面挂起,最终显示错误,我注意到我可以在任务管理器中看到 soffice.bin 和 soffice.exe 进程在我的 IIS 用户名下运行。
这是错误:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `com.sun.star.ServiceManager': Server execution failed ' in C:\WEB_ROOT\SoftwareContract\WordToPdf.php:14 Stack trace: #0 C:\WEB_ROOT\SoftwareContract\WordToPdf.php(14): com->com('com.sun.star.Se...') #1 C:\WEB_ROOT\SoftwareContract\Index.php(11): word2pdf('file:///C:/web_...', 'file:///C:/web_...') #2 {main} thrown in C:\WEB_ROOT\SoftwareContract\WordToPdf.php on line 14
我已经在这些领域仔细检查了我的 IIS 用户的权限:
C:\PHP
C:\Program Files\OpenOffice.org 3
C:\Program Files\Java
C:\WEB_ROOT ---- location for my php code
在每种情况下,我的 IIS 用户都具有以下权限:读取和执行、列出文件夹内容、读取。并且在每种情况下,都没有检查“拒绝”来抵消权限。我还授予 IIS 用户对 php 代码所在的 Web_Root 文件夹的写入权限。
这是调用转换函数 WordToPdf 的 php:
<?php
require_once('WordToPdf.php');
$output_dir = 'C:/web_root/softwarecontract/';
$doc_file = 'C:/web_root/softwarecontract/testdoc.rtf';
$pdf_file = 'output.pdf';
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
word2pdf($doc_file,$output_file);
?>
这是 WordToPdf.php:
<?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));
//Write out the PDF
$oWriterDoc->storeToURL($output_url,$export_args);
$oWriterDoc->close(true);
}
?>
我的权限是否有任何问题,或者我需要检查 IIS 用户权限的任何其他区域?如果不是权限问题,有谁知道为什么 IIS 无法创建 COM 对象?
谢谢!!