您不能使用Office Interop来自动化这样的任务,可以在此处查看Microsoft的原因:
https://support.microsoft.com/en-us/kb/257757
最佳方法是使用强大的库,如Aspose.Slides(与ppt、pptx兼容,强大的操作),它们被设计为用作API。
您可以通过NetPhp库从PHP中使用Aspose.Slides。这里有一个示例:
http://www.drupalonwindows.com/en/blog/powerpoint-presentation-images-php-drupal-example
相关的代码如下,其中包含一些Drupal特定的内容,但您可以看到它是如何工作的,并在其他地方使其正常运行:
protected function processFilePowerpoint(array $file, array &$files) {
$netphp = \Drupal::service('netphp');
$runtime = $netphp->getRuntime();
$runtime->RegisterAssemblyFromFile("libraries/_bin/aspose/Aspose.Slides.dll", "Aspose.Slides");
$runtime->RegisterAssemblyFromFullQualifiedName("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing");
$destination = strtr(PresentacionSlide::UPLOAD_LOCATION, ['[envivo_presentacion:id]' => $this->entity->id()]);
file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$sourcefile = drupal_realpath($file['tmppath']);
$presentation = $runtime->TypeFromName("Aspose.Slides.Presentation")->Instantiate($sourcefile);
$format = $runtime->TypeFromName("System.Drawing.Imaging.ImageFormat")->Png;
$x = 0;
$slides = $presentation->Slides->AsIterator();
foreach ($slides as $slide) {
$x++;
$bitmap = $slide->GetThumbnail(1, 1);
$destinationfile = $destination . "\\slide_{$x}.png";
$bitmap->Save(drupal_realpath($destinationfile), $format);
$files[] = PresentacionSlide::fromFile($destinationfile);
}
$presentation->Dispose();
}