PHPPowerpoint设置幻灯片宽度高度

时间:2013-11-12 09:24:51

标签: php powerpoint phppowerpoint

我想知道是否有办法创建一个具有预定义宽度和高度的ppt文件,而不是默认宽度和高度。

谢谢你, 基兰

4 个答案:

答案 0 :(得分:2)

我已使用此代码为新的PHPPresentation(较新的PHPPowerpoint版本)设置它。 希望它有所帮助..(用你的代表路径取代路径 以及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);

答案 1 :(得分:1)

The answer of @user2633993仍然有效,但设置布局宽度和高度的代码稍有变化,现在需要设置一个包含public class Main { public static void main(String[] args) { Circle c1 = new Circle(5.8); foo(c1); System.out.println(c1); } public static void foo(Circle c){ c = null; } } cx键的数组,价值并不重要。

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

cy

答案 2 :(得分:0)

你可以设置宽度和高度:

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

答案 3 :(得分:0)

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

$objPHPPowerPoint->getLayout()
                 ->setCX(841, DocumentLayout::UNIT_MILLIMETER)
                 ->setCY(1189, DocumentLayout::UNIT_MILLIMETER);