2

我正在寻找一个 PHP 代码或 PHP 库来将 microsoft doc/docx 文件转换为 PDF。我对 Zend 不熟悉。请帮我成功地将我的word文件转换为PDF。

4

4 回答 4

1

打开办公室,这段代码对我有帮助:)

<?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:/wamp/www/vineesh/";
    $doc_file = "C:/wamp/www/vineesh/vineesh.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);
    ?>
于 2013-01-03T09:55:56.240 回答
0

你是说 PHP 库吗?然后phpdocx将为您工作。浏览有关安装和生成 pdf 的文档。

于 2012-12-24T08:18:28.520 回答
0

phpword 不会转换为 PDF,它仅有助于创建 word 文档并在其上使用变量替换。

于 2013-01-18T19:14:10.413 回答
0

如果你在 Windows 上,COM 包是最好的选择。

于 2014-02-27T08:46:17.890 回答