I want to know if there is a way to create a ppt file with pre defined width and height rather than default one.
Asked
Active
Viewed 4,692 times
4
-
Please would you show what you have tried? – Suleman Ahmad Nov 12 '13 at 09:34
-
2Have you checked `PHPPowerPoint_DocumentLayout::setDocumentLayout`, `PHPPowerPoint_DocumentLayout::setLayoutXmilli` or `PHPPowerPoint_DocumentLayout::setLayoutYmilli`? [Their source code can be found here](https://github.com/PHPOffice/PHPPowerPoint/blob/master/Classes/PHPPowerPoint/DocumentLayout.php) – h2ooooooo Nov 12 '13 at 09:41
3 Answers
4
I've used this code to set it for the new PHPPresentation (newer PHPPowerpoint version).
Hope it helps..(replace path's with your phppresentation path's
and width(1180)
and height(768)
to suit yours
/*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);

Shawn Mehan
- 4,513
- 9
- 31
- 51

Vinu
- 89
- 5
2
The answer of @user2633993 is still valid, though the code for setting the layout width and height has changed a bit, now you need to set an array containing the cx
and cy
keys, their values doesn't matter.
So the code needs to look something like this:
$objPHPPowerPoint->getLayout()->setDocumentLayout(['cx' => 1280, 'cy' => 700], true)
->setCX(1280, DocumentLayout::UNIT_PIXEL)
->setCY(700, DocumentLayout::UNIT_PIXEL);`

gkubed
- 1,849
- 3
- 32
- 45
0
you can set width and height:
$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__));

Suleman Ahmad
- 2,025
- 4
- 28
- 43
-
1This has nothing to do with [`PHPPowerpoint`](https://github.com/PHPOffice/PHPPowerPoint) though. – h2ooooooo Nov 12 '13 at 09:38