0
votes

I want to convert a PPT/PPTX to PDF using COM extension for PHP under Windows. I struggled a lot without any succes using ExportAsFixedFormat and I used instead SaveAs method(). The PDF does get generated but the script never finishes. Opening Task Manager I can see that the PowerPoint process is still running... I can't get it to close.

With Word everything works fine with this code:

$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);

With PowerPoint I'm using this code with no luck:

$powerpnt = new COM('powerpoint.application') or die('Unable to load PowerPoint');
$powerpnt->Visible = true;

// Open an existing document
$doc = $powerpnt->Presentations->Open('powerpoint.pptx');
$doc->SaveAs('powerpoint.pdf', 32, 1);

$doc->Close();

$powerpnt->Quit();
$powerpnt = null;
unset($powerpnt);

I also tried, but still without working:

$powerpnt->Presentations[1]->Close();
$powerpnt->Presentations("powerpoint.pptx")->Close();
$powerpnt->ActivePresentation->Close(); // this generates an error

I would really appreciate some insight. Thank you

1
If there's a line that throws an error, then do post that error. Besides, you don't need to set the $powerpnt to null or unset it. As soon as there are no more references to it, it will be automatically GC'ed.lxg
$powerpnt->ActivePresentation->Close(false) generates this error: Fatal error: Uncaught exception 'com_exception' with message '( ! ) com_exception: Error [0x80020011] Does not support a collection.' Without the false argument this script never finishes.sergio

1 Answers

0
votes

You must specify exact path so change : $doc = $powerpnt->Presentations->Open('powerpoint.pptx'); $doc->SaveAs('powerpoint.pdf', 32, 1);

TO: $doc = $powerpnt->Presentations->Open('D:\powerpoint.pptx'); $doc->SaveAs('D:\powerpoint.pdf', 32, 1);