PHPPresentation基本用途

基本示例

以下是 PHPPresentation 库的一个基本示例。更多示例请参见 samples 文件夹

require_once 'src/PhpPresentation/Autoloader.php';
\PhpOffice\PhpPresentation\Autoloader::register();
$objPHPPresentation = new PhpPresentation();
// Create slide
$currentSlide = $objPHPPresentation->getActiveSlide();
// Create a shape (drawing)
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
      ->setDescription('PHPPresentation logo')
      ->setPath('./resources/phppresentation_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($objPHPPresentation, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPresentation, 'ODPresentation');
$oWriterODP->save(__DIR__ . "/sample.odp");

文档信息

您可以设置文档信息,如标题、创建者和公司名称。请使用以下函数:

$properties = $objPHPPresentation->getProperties();
$properties->setCreator('My name');
$properties->setCompany('My factory');
$properties->setTitle('My title');
$properties->setDescription('My description');
$properties->setCategory('My category');
$properties->setLastModifiedBy('My name');
$properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
$properties->setSubject('My subject');
$properties->setKeywords('my, key, word');

演示文稿属性

您可以定义一些与演示文稿相关的属性,如缩放或缩略图

注释

您可以通过setCommentVisible方法定义演示文稿是否显示注释。

$oPresentation = new PhpPresentation();
$oProperties = $oPresentation->getPresentationProperties();
// Get the display for comment
var_export($oProperties->isCommentVisible());
// Output : false
// Enable the display for comment
$oProperties->setCommentVisible(true);
// Get the display for comment
var_export($oProperties->isCommentVisible());
// Output : true

最后查看

您可以使用setLastView方法定义演示文稿的最后查看。

$oPresentation = new PhpPresentation();
$oProperties = $oPresentation->getPresentationProperties();
// Get the last view of the presentation
echo $oProperties->getZoom();
// Output : PresentationProperties::VIEW_SLIDE
// Set the last view of the presentation
$oProperties->setLastView(PresentationProperties::VIEW_NOTES);
// Get the last view of the presentation
echo $oProperties->getZoom();
// Output : PresentationProperties::VIEW_NOTES

缩略图

您可以使用setThumbnailPath方法定义演示文稿的缩略图。

$oPresentation = new PhpPresentation();
$oProperties = $oPresentation->getPresentationProperties();
// Set path of the thumbnail
$oProperties->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
// Get path of the thumbnail
echo $oProperties->getThumbnailPath();

缩放

您可以使用setZoom方法定义演示文稿的缩放比例。

$oPresentation = new PhpPresentation();
$oProperties = $oPresentation->getPresentationProperties();
// Get zoom of the presentation
echo $oProperties->getZoom();
// Output : 1
// Set zoom of the presentation (3 = 300%)
$oProperties->setZoom(3);
// Get zoom of the presentation
echo $oProperties->getZoom();
// Output : 3

本文为翻译内容, 英文原文地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑牛儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值