Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Uncaught exception 'com_exception' with message. while converting ppt to jpg

When I run blow code:

/*** PPT to Image conversion ***/
$ppt_file = 'E:\wamp\www\temp/a.pptx';
$app = new COM("PowerPoint.application") or die("Unable to instantiate PowerPoint");
$app->Visible = true;
$app->Presentations->Open($ppt_file); 
$app->Presentations[1]->SaveAs("E:/tmp/outdir",18);
$app->Presentations[1]->Close();
$app->Quit();
$app = null; 

It gives me one exception :

Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107 Stack trace: #0 E:\wamp\www\temp\video_conversion.php(107): variant->Open('E:\wamp\www\tem...') #1 {main} thrown in E:\wamp\www\temp\video_conversion.php on line 107

I am unable to figure out what is the problem.

like image 693
Ravi Sharma Avatar asked May 21 '12 12:05

Ravi Sharma


3 Answers

This is kind of issue is due to the following factors.

  1. PHP.ini settings
  2. Folder Permission
  3. allow open is not enabled in the server
  4. allowed upload size
like image 196
Johndave Decano Avatar answered Oct 27 '22 04:10

Johndave Decano


Within your error, you see the following message: PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107

Does the PHP user have permissions to the file E:\wamp\www\temp/a.pptx?

Try correcting your slashes: E:\wamp\www\temp\a.pptx as / normally refers to an option or argument.

At the end of the day, it appears to be a permissions error, a location issue or alike which is preventing access to that file. Can you open the file with fopen or file_get_contents?

like image 34
Mike Mackintosh Avatar answered Oct 27 '22 04:10

Mike Mackintosh


Try this with com class:

COM class Reference: - http://us2.php.net/manual/en/class.com.php

<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
    $ppApp = new COM("PowerPoint.Application");
    $ppApp->Visible = True;

    $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp

    $ppName = "MySlides.ppt";
    $FileName = "MyPP";

    //*** Open Document ***//
    $ppApp->Presentations->Open(realpath($ppName));

    //*** Save Document ***//
    $ppApp->ActivePresentation->SaveAs($strPath."/".$FileName,17);  //'*** 18=PNG, 19=BMP **'
    //$ppApp->ActivePresentation->SaveAs(realpath($FileName),17);

    $ppApp->Quit;
    $ppApp = null;
?>
PowerPoint Created to Folder <b><?=$FileName?></b>
</body>
</html>

Or try this :

$powerpnt = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint");

$presentation = $powerpnt->Presentations->Open(realpath($file), false, false, false) or die("Unable to open presentation");

foreach($presentation->Slides as $slide)

{

    $slideName = "Slide_" . $slide->SlideNumber;

    $exportFolder = realpath($uploadsFolder);

    $slide->Export($exportFolder."\\".$slideName.".jpg", "jpg", "600", "400");

}

$powerpnt->quit();
like image 42
Abid Hussain Avatar answered Oct 27 '22 05:10

Abid Hussain