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
$powerpnt
tonull
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 thefalse
argument this script never finishes. – sergio