doupi3874 2014-10-27 23:17
浏览 157

PHP COM PowerPoint另存为PDF和关闭演示文稿

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条回答 默认 最新

  • douxun2023 2016-11-01 15:33
    关注

    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);

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决