首页  >  文章  >  后端开发  >  php调用com组件将ppt转为图片

php调用com组件将ppt转为图片

零下一度
零下一度原创
2017-06-23 14:39:092773浏览

 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