在PHP中将Word文档转换为PDF时出错

时间:2019-03-08 17:16:03

标签: php apache openoffice.org

我一直在尝试使用下面给出的php代码将word doc文件转换为pdf并 我得到error message

  

致命错误:在以下目录的C:\ xampp \ htdocs \ pdf \ index.php中找不到类'COM'   第12行

代码:

<?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){
    //echo $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:/Users/shubh/Desktop";
    $doc_file = "C:/Users/shubh/Desktop/temp.docx";
    $pdf_file = "vineesh.pdf";
    $output_file = $output_dir . $pdf_file;
    $doc_file = "file:///" . $doc_file;
    $output_file = "file:///" . $output_file;
    word2pdf($doc_file,$output_file);
?>

请尝试帮助我。...将不胜感激。

0 个答案:

没有答案