PHPPresentation
PHPPresentation copied to clipboard
Linespacing not working (not implemented)
$shape->getActiveParagraph()->setLineSpacing(300); has no effect on the line spacing of a paragraph;
I managed to fix it (implement line spacing for both odp and pptx) by adding in
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%');
to /src/PhpPresentation/Writer/ODPresentation/Content.php in the Switch statement (from line 201) for paragraph properties, e.g.,
switch ($item->getAlignment()->getHorizontal()) {
case Alignment::HORIZONTAL_LEFT:
$objWriter->writeAttribute('fo:text-align', 'left');
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
break;
case Alignment::HORIZONTAL_RIGHT:
$objWriter->writeAttribute('fo:text-align', 'right');
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
break;
case Alignment::HORIZONTAL_CENTER:
$objWriter->writeAttribute('fo:text-align', 'center');
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
break;
case Alignment::HORIZONTAL_JUSTIFY:
$objWriter->writeAttribute('fo:text-align', 'justify');
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
break;
case Alignment::HORIZONTAL_DISTRIBUTED:
$objWriter->writeAttribute('fo:text-align', 'justify');
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); /added
break;
default:
$objWriter->writeAttribute('fo:text-align', 'left');
$objWriter->writeAttribute('fo:line-height', $item->getLineSpacing().'%'); //added
break;
}
and then for pptx, I changed line 526 in /src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php to:
//$objWriter->writeAttribute('val', $paragraph->getLineSpacing() . "%");
$objWriter->writeAttribute('val', $paragraph->getLineSpacing()*1000);
Voila.
In the actual presentation script to change the line spacing for a paragraph, it needs to be called "after" the paragraph in question, e.g.,
$shape->createTextRun('the paragraph that should have increased line spacing'); $shape->getActiveParagraph()->setLineSpacing(150); // 150 = 1.5 x times normal line spacing
hope this helps someone.