4

我想知道是否有一种方法可以创建具有预定义宽度和高度而不是默认值的 ppt 文件。

4

4 回答 4

4

我已使用此代码为新的 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);
于 2015-10-05T17:33:44.330 回答
2

@user2633993 的答案仍然有效,虽然设置布局宽度和高度的代码发生了一些变化,现在您需要设置一个包含cxcy键的数组,它们的值无关紧要。

所以代码需要看起来像这样:

$objPHPPowerPoint->getLayout()->setDocumentLayout(['cx' => 1280, 'cy' => 700], true)
        ->setCX(1280, DocumentLayout::UNIT_PIXEL)
        ->setCY(700, DocumentLayout::UNIT_PIXEL);`
于 2017-06-14T19:59:21.350 回答
0

您可以设置宽度和高度:

请看这个教程

$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__));
于 2013-11-12T09:36:40.087 回答
-1

在最新版本 (v0.9.0) 中,您不再需要将数组设置为提到的 @user2962785。以下就足够了(示例是 A0 纵向格式)

$objPHPPowerPoint->getLayout()
                 ->setCX(841, DocumentLayout::UNIT_MILLIMETER)
                 ->setCY(1189, DocumentLayout::UNIT_MILLIMETER);
于 2019-12-07T22:32:43.620 回答