windows office com组件 php pptx转pdf

1.


2.修改office的dcom组件

comexp.msc

如果找不到就看一下安装的office的位数  

32位的用 

comexp.msc -32

看恩吧

看恩吧

右键属性

看恩吧

看恩吧

看恩吧


看恩吧

看恩吧

双击选中 everyone


看恩吧


看恩吧


看恩吧

同样添加everyone


看恩吧




55.

public function ppt_to_pdf() {
        $srcfilename = 'E:/aa.ppt';
        $destfilename = 'E:/aa.pdf';
        try {
            if(!file_exists($srcfilename)){
                return;
            }
            $ppt = new \COM("powerpoint.application") or die("Unable to instantiate Powerpoint");
            $presentation = $ppt->Presentations->Open($srcfilename, false, false, false);
            $presentation->SaveAs($destfilename,32,1);
            $presentation->Close();
            $ppt->Quit();
        } catch (\Exception $e) {
            if (method_exists($ppt, "Quit")){
                $ppt->Quit();
            }
            return;
        }
    }
public function excel_to_pdf() {
        $srcfilename = 'E:/aa.xls';
        $destfilename = 'E:/aa.pdf';
        try {
            if(!file_exists($srcfilename)){
                return;
            }
            $excel = new \COM("excel.application") or die("Unable to instantiate excel");
            $workbook = $excel->Workbooks->Open($srcfilename, null, false, null, "1", "1", true);
            $workbook->ExportAsFixedFormat(0, $destfilename);
            $workbook->Close();
            $excel->Quit();
        } catch (\Exception $e) {
             echo ("src:$srcfilename catch exception:" . $e->__toString());
            if (method_exists($excel, "Quit")){
                $excel->Quit();
            }
            return;
        }
    }


 public function doc_to_pdf() {
        $srcfilename = 'E:/aa.doc';
        $destfilename = 'E:/aa.pdf';
        try {
            if(!file_exists($srcfilename)){
                return;
            }
 
            $word = new \COM("word.application") or die("Can't start Word!");
            $word->Visible=0;
            $word->Documents->Open($srcfilename, false, false, false, "1", "1", true);
           
            $word->ActiveDocument->final = false;
            $word->ActiveDocument->Saved = true;
            $word->ActiveDocument->ExportAsFixedFormat(
                $destfilename,
                17,                         // wdExportFormatPDF
                false,                      // open file after export
                0,                          // wdExportOptimizeForPrint
                3,                          // wdExportFromTo
                1,                          // begin page
                5000,                       // end page
                7,                          // wdExportDocumentWithMarkup
                true,                       // IncludeDocProps
                true,                       // KeepIRM
                1                           // WdExportCreateBookmarks
            );
            $word->ActiveDocument->Close();
            $word->Quit();
        } catch (\Exception $e) {
            if (method_exists($word, "Quit")){
                $word->Quit();
            }
            return;
        }
    }


打赏

看恩吧
网站不承担任何有关评论的责任
  • 最新评论
  • 总共条评论
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦