我已完成PhpPresentation(master分支)的手动安装,我试图运行该软件包附带的一个简单示例,但我无法正常运行。我已经完成了大量关于如何解决的研究,但无济于事。请参阅下面的代码以及我一直收到的错误。
<?php
require_once 'C:/wamp/www/Classes/PHPPresentation-master/PHPPresentation-master/src/PhpPresentation/Autoloader.php';
\PhpOffice\PhpPresentation\Autoloader::register();
require_once 'C:/wamp/www/Classes/Common-master/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
$objPHPPowerPoint = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath('./resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor( new Color( 'FFE06B20' ) );
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(__DIR__ . "/sample.odp");
?>
这是我收到的错误:
致命错误:未捕获的异常&#39;异常&#39;消息&#39;文件./resources/phppowerpoint_logo.gif未找到!&#39;在第34行的C:\ wamp \ www \ Classes \ PHPPresentation-master \ PHPPresentation-master \ src \ PhpPresentation \ Shape \ Drawing \ File.php
虽然当我去寻找时,gif图像就在那里......任何帮助理解这一点都是值得赞赏的。
由于
答案 0 :(得分:0)
在使用PHPpresentation时,我也经常遇到此类错误。 gif图像必须放置在资源文件夹中,而不是在图片文件夹中。尝试通过在资源文件夹中创建一个具有相同名称的示例图像来执行。对我有用