word转pdf实践

in 后端 with 0 comment

参考seafile文档

linux环境

apt-get install libreoffice libreoffice-headless
sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy
soffice --headless --invisible --convert-to pdf /tmp/abc.docx --outdir /tmp/

windows环境
php启用com扩展

添加:extension=com_dotnet.dll 
去除注释:com.allow_dcom = true
    $doc = dirname(__FILE__) . "/index.doc";
    $pdf = dirname(__FILE__) . "/index.pdf";

    $word = new COM("Word.Application") or die ("Could not initialise Object.");
    // 或者 $dd = $word = new COM("Word.Application") or die ("Could not initialise Object.");
    // set it to 1 to see the MS Word window (the actual opening of the document)
    $word->Visible = 0;
    // recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
    $word->DisplayAlerts = 0;
    // open the word 2007-2013 document

    $word->Documents->Open($doc);

    $word->ActiveDocument->ExportAsFixedFormat($pdf, 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
    // quit the Word process
    $word->Quit(false);
Comments are closed.