首頁  >  文章  >  後端開發  >  php調用com組件將ppt轉為圖片

php調用com組件將ppt轉為圖片

零下一度
零下一度原創
2017-06-23 14:39:092778瀏覽

 PHP 呼叫com元件將ppt轉換為圖片。

需要在php.ini開啟

extension=php_com_dotnet.dll
com.allow_dcom = true
 
測試程式碼如下:
 
<?php
$powerpnt = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint");
$file=&#39;1.ppt&#39;;
echo realpath($file);

$addr = $_SERVER[&#39;DOCUMENT_ROOT&#39;].&#39;/ppt/1.ppt&#39;;
echo $addr;
$presentation = $powerpnt->Presentations->Open($addr, false, false, false) or die("Unable to open presentation");


$presentation->Fonts->Replace(&#39;黑体&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;MS Gothic&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;方正粗倩简体&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;方正小标宋简体&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;Arial Black&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;华文中宋&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;Arial Unicode MS&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;方正细圆简体&#39;,&#39;幼圆&#39;);
$presentation->Fonts->Replace(&#39;Times New Roman&#39;,&#39;幼圆&#39;);


foreach($presentation->Fonts as $c)
{
	echo $c->name."<br />";
	//echo $c->Replace(&#39;&#39;,&#39;&#39;);
}


foreach($presentation->Slides as $slide)
{
$slideName = "Slide_" . $slide->SlideNumber;
$uploadsFolder = &#39;iii&#39;;
$exportFolder = realpath($uploadsFolder);
$slide->Export($exportFolder."//".$slideName.".jpg", "jpg", "1920", "1080");
}
$presentation->Close();
$powerpnt->Quit();
$powerpnt = null;
?>

  

在win7上跑,沒問題,放到2008上面出現錯誤,有一種exception叫unknown. ..

解決方案:

cmd -》 dcomcnfg

 

#

以上是php調用com組件將ppt轉為圖片的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn