Home  >  Article  >  Backend Development  >  PHP calls the com component to convert ppt to pictures

PHP calls the com component to convert ppt to pictures

零下一度
零下一度Original
2017-06-23 14:39:092803browse

PHP calls the com component to convert ppt to pictures.

Needs to be enabled in php.ini

extension=php_com_dotnet.dll
com.allow_dcom = true
The test code is as follows:
<?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;
?>

 

When running on win7, there is no problem. However, when running on 2008, an error occurs. There is an exception called unknown. ..

Solution:

cmd -》 dcomcnfg

##

The above is the detailed content of PHP calls the com component to convert ppt to pictures. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn