PHP 生成 ppt,PhpPresentation生成ppt

public function toPPT() {

$objPHPPresentation = new PhpPresentation(); //创建对象

$objPHPPresentation->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_B5ISO); //设置ppt比例

//也可以自定义宽高

//$objPHPPresentation->getLayout()->setCX( 1450, DocumentLayout::UNIT_PIXEL)->setCY( 800,DocumentLayout::UNIT_PIXEL);

$currentSlide = $objPHPPresentation->getActiveSlide(); //获取第一张幻灯片

//设置PPT背景图片

$imgPath = '';

$oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Image();

$oBackground->setPath($imgPath);

$currentSlide->setBackground($oBackground);

//添加一个文本框

$shape = $currentSlide->createRichTextShape()

->setHeight(50) //高

->setWidth(50) //宽

->setOffsetX(50) //X轴偏移量

->setOffsetY(50); //Y轴偏移量

//设置文本框样式

$shape->getBorder()

->setLineStyle(\PhpOffice\PhpPresentation\Style\Border::LINE_SINGLE) //单行线

->setLineWidth(2) //宽度

->setDashStyle(\PhpOffice\PhpPresentation\Style\Border::DASH_SYSDASH) //虚线

->getColor()->setARGB(\PhpOffice\PhpPresentation\Style\Color::COLOR_DARKBLUE); //颜色

//->setColor(new \PhpOffice\PhpPresentation\Style\Color::COLOR_DARKBLUE);

//设置文本框内字体

$shape->getActiveParagraph()->getAlignment()->setHorizontal( \PhpOffice\PhpPresentation\Style\Alignment::HORIZONTAL_LEFT ); //偏左 居中 偏右

$textRun = $shape->createTextRun('这是你要写的文字');

$textRun->getFont()

->setBold(true) //是否加粗

->setSize(34) //字体大小

->setName('微软雅黑') //字体样式

->setColor( new \PhpOffice\PhpPresentation\Style\Color('FFFF0000') ); //字体颜色

//添加一张图片

$shape = $currentSlide->createDrawingShape();

$img = '';

$shape->setPath($img)

->setHeight(40)

->setWidth(40)

->setOffsetX(40) //X轴偏移量

->setOffsetY(40); //Y轴偏移量

$shape->getShadow()->setVisible(true); //这句话没有具体研究,图片样式,如果需要,自行看源代码

//再新建一张幻灯片

$currentSlide = $objPHPPresentation->createSlide();

//保存 如果上面是自定义PPT宽高 请不要加第二个参数

$oWriterPPTX = \PhpOffice\PhpPresentation\IOFactory::createWriter($objPHPPresentation,'PowerPoint2007');

$oWriterPPTX->save('fileName');

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值