Skip to content

Vertical alignment does not work if it is a placeholder #799

Open
@NigelSwinson

Description

@NigelSwinson

The following sample demonstrates that if you have an entity in a slide (or a slide layout) which has Alignment::Vertical_CENTER, then it will only be aligned center if the object does not also have a PlaceHolder. Horizontal alignment is however respected in both cases.

<?php

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Placeholder;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;

include_once 'Sample_Header.php';

// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();

// Set properties
echo date('H:i:s') . ' Set properties' . EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation Team')
->setTitle('Sample 20 SlideLayout')
->setSubject('Sample 20 Subject')
->setDescription('Sample 20 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');

// Create slide
echo date('H:i:s') . ' Create slide' . EOL;
$currentSlide = $objPHPPresentation->getActiveSlide();

echo date('H:i:s') . ' Create SlideLayout' . EOL;
$slideLayout = $objPHPPresentation->getAllMasterSlides()[0]->createSlideLayout();
$slideLayout->setLayoutName('Sample Layout');

$slides = array($slideLayout, $objPHPPresentation->getActiveSlide());

foreach ($slides as $slide) {
	echo date('H:i:s') . ' Create Footer' . EOL;
	$footerTextShape = $slide->createRichTextShape();
	$footerTextShape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER));
	
	$footerTextShape
	->setOffsetX(77)
	->setOffsetY(0)
	->setWidth(448)
	->setHeight(223);
	
	$footerTextRun = $footerTextShape->createTextRun('With setPlaceholder');
	$footerTextRun->getFont()
	->setName('Calibri')
	->setSize(9)
	->setColor(new Color(Color::COLOR_DARKGREEN))
	->setBold(true);
	$footerTextShape->getActiveParagraph()->getAlignment()
	->setVertical(Alignment::VERTICAL_CENTER);
	
	$footerTextShape = $slide->createRichTextShape();
	//$footerTextShape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER));
	
	$footerTextShape
	->setOffsetX(77)
	->setOffsetY(479)
	->setWidth(448)
	->setHeight(223);
	
	$footerTextRun = $footerTextShape->createTextRun('Without placeholder');
	$footerTextRun->getFont()
	->setName('Calibri')
	->setSize(9)
	->setColor(new Color(Color::COLOR_DARKGREEN))
	->setBold(true);
	$footerTextShape->getActiveParagraph()->getAlignment()
	->setVertical(Alignment::VERTICAL_CENTER);
}

echo date('H:i:s') . ' Apply Layout' . EOL;
$currentSlide->setSlideLayout($slideLayout);

// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
if (!CLI) {
	include_once 'Sample_Footer.php';
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions