PHPPresentation icon indicating copy to clipboard operation
PHPPresentation copied to clipboard

Create slide and paragraph that fit document

Open bUxEE opened this issue 4 years ago • 0 comments

I have been having a hard time to accomplish a simple task:

I am creating mutiple slides that need to contain only text which should be autosized to fit the slide. I create a presentation and set to LAYOUT_SCREEN_4X3 $presentation = new PhpPresentation(); $presentation->getLayout()->setDocumentLayout(LAYOUT_SCREEN_4X3, true);

I then generate the slides in a loop, for each slide i create a createRichTextShape, then a paragraph, and multiple createTextRun inside the paragraph.

The problem is that the resulting paragraph does not cover the whole slide, and thus does not resize the inner text which overflows out of it. Modifying the generated ppt in powerpoint and simply resizing the paragraph to fit the whole slide wraps all the text inside it and resizes it correctly.

$currentSlide = $presentation->createSlide();
$currentSlide->setName("Slide name");

$shape = $currentSlide->createRichTextShape()
	->setHeight(400) //problem here? how can i know the right height for LAYOUT_SCREEN_4X3
	->setWidth(600) //problem here? how can i know the right width for LAYOUT_SCREEN_4X3
	->setOffsetX(40)
      	 ->setOffsetY(40)
	->setHorizontalOverflow(RichText::OVERFLOW_CLIP)
	->setVerticalOverflow(RichText::OVERFLOW_CLIP)
	->setWrap(RichText::WRAP_SQUARE);
 $shape->createParagraph(); // Can i set the paragraph size to fill the slide and wrap all createTextRus inside it?
 $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT); 
 $textRun = $shape->getActiveParagraph()->createTextRun("TEXT HERE");
 $textRun->getFont()->setSize(14);
 $shape->getActiveParagraph()->createBreak();
 $textRun = $shape->getActiveParagraph()->createTextRun("TEXT 2 HERE"); // N repeated textruns will be present;

bUxEE avatar Mar 20 '20 14:03 bUxEE