【问题标题】:PhpPowerpoint set slide width and height (slide dimensions)PhpPowerpoint 设置幻灯片宽度和高度(幻灯片尺寸)
【发布时间】:2013-11-12 09:24:50
【问题描述】:
我想知道是否有一种方法可以创建具有预定义宽度和高度而不是默认值的 ppt 文件。
【问题讨论】:
-
-
您是否检查过PHPPowerPoint_DocumentLayout::setDocumentLayout、PHPPowerPoint_DocumentLayout::setLayoutXmilli 或PHPPowerPoint_DocumentLayout::setLayoutYmilli? Their source code can be found here
-
标签:
php
powerpoint
phppowerpoint
odp
【解决方案1】:
我已使用此代码为新的 PHPPresentation(较新的 PHPPowerpoint 版本)设置它。
希望它有帮助..(用你的 phppresentation 路径替换路径
和width(1180) 和height(768) 适合你的
/*Standard library loaders */
require_once 'include/Common/src/Common/Autoloader.php';
\PhpOffice\Common\Autoloader::register();
require_once 'include/PHPPowerPoint2/src/PhpPresentation/Autoloader.php';
\PhpOffice\PhpPresentation\Autoloader::register();
/*Standard library loaders */
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\DocumentLayout;
$objPHPPowerPoint = new PhpPresentation();
$objPHPPowerPoint->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_CUSTOM, true)
->setCX( 1180, DocumentLayout::UNIT_PIXEL)
->setCY( 768, DocumentLayout::UNIT_PIXEL);
【解决方案2】:
The answer of @user2633993 仍然有效,虽然设置布局宽度和高度的代码发生了一些变化,现在您需要设置一个包含cx 和cy 键的数组,它们的值无关紧要。
所以代码需要看起来像这样:
$objPHPPowerPoint->getLayout()->setDocumentLayout(['cx' => 1280, 'cy' => 700], true)
->setCX(1280, DocumentLayout::UNIT_PIXEL)
->setCY(700, DocumentLayout::UNIT_PIXEL);`
【解决方案3】:
你可以设置宽度和高度:
Please see this tutorial
$objPHPPowerPoint = new PHPPowerPoint();
$currentSlide = $objPHPPowerPoint->getActiveSlide();
$shape = $currentSlide->createDrawingShape();
$shape = $currentSlide->createRichTextShape();
$shape->setHeight(300);
$shape->setWidth(600);
$shape->setOffsetX(170);
$shape->setOffsetY(180);
$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setBold(true);
$textRun->getFont()->setSize(60);
$textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FFC00000' ) );
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$objWriter->save(str_replace('.php', '.pptx', __FILE__));
【解决方案4】:
在最新版本 (v0.9.0) 中,您不再需要将数组设置为提到的@user2962785。以下就足够了(以A0纵向格式为例)
$objPHPPowerPoint->getLayout()
->setCX(841, DocumentLayout::UNIT_MILLIMETER)
->setCY(1189, DocumentLayout::UNIT_MILLIMETER);