【问题标题】:PhpPowerpoint set slide width and height (slide dimensions)PhpPowerpoint 设置幻灯片宽度和高度(幻灯片尺寸)
【发布时间】:2013-11-12 09:24:50
【问题描述】:

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

【问题讨论】:

  • 请您展示您尝试过的内容吗?
  • 您是否检查过PHPPowerPoint_DocumentLayout::setDocumentLayoutPHPPowerPoint_DocumentLayout::setLayoutXmilliPHPPowerPoint_DocumentLayout::setLayoutYmilliTheir source code can be found here
  • @h2oooo 谢谢你成功了

标签: 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 仍然有效,虽然设置布局宽度和高度的代码发生了一些变化,现在您需要设置一个包含cxcy 键的数组,它们的值无关紧要。

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

    $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);
      

      【讨论】:

        猜你喜欢
        • 2021-03-02
        • 1970-01-01
        • 2014-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-28
        相关资源
        最近更新 更多