Skip to content

Commit

Permalink
PowerPoint2007 Writer: Enable style and position of a Placeholder
Browse files Browse the repository at this point in the history
* Create SlideLayout Sample
* When write a Placeholder, fetch the first element of the first paragraph to apply style
>
>
Co-authored-by: Quentin Machard <[email protected]>
Co-authored-by: Progi1984 <[email protected]>
  • Loading branch information
Quentin Machard authored and Progi1984 committed Dec 13, 2023
1 parent 85c7821 commit 21b20d2
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 138 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
"php samples/Sample_17_Comment.php",
"php samples/Sample_18_Animation.php",
"php samples/Sample_19_SlideMaster.php",
"php samples/Sample_20_ExternalSlide.php"
"php samples/Sample_20_SlideLayout.php",
"php samples/Sample_21_AutoShape.php",
"php samples/Sample_22_ExternalSlide.php"
]
}
}
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- ODPresentation Writer
- PowerPoint2007 Reader
- PowerPoint2007 Writer
- PowerPoint2007 Writer: Enable style and position of a Placeholder - [@qmachard](https://github.com/qmachard) in [#787](https://github.com/PHPOffice/PHPPresentation/pull/787)

## Improvements
- Slide : Raised max value for identifier rand call - [@Scheissy](https://github.com/Scheissy) in [#777](https://github.com/PHPOffice/PHPPresentation/pull/777)
Expand Down
8 changes: 4 additions & 4 deletions samples/Sample_19_SlideMaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
->setVertical(Alignment::VERTICAL_BASE);
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
$textRun = $shape->createTextRun('01-02-2000')->getFont()->setSize(18);
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_DATETIME))->getPlaceholder()->setIdx(10);
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_DATETIME));
// Footer placeholder
$shape = $oMasterSlide->createRichTextShape();
$shape->setWidthAndHeight(468, 38)->setOffsetX(246)->setOffsetY(680);
Expand All @@ -64,16 +64,16 @@
->setVertical(Alignment::VERTICAL_BASE);
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
$textRun = $shape->createTextRun('Placeholder for Footer')->getFont()->setSize(18);
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER))->getPlaceholder()->setIdx(11);
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER));
// Slidenumber placeholder
$shape = $oMasterSlide->createRichTextShape();
$shape->setWidthAndHeight(140, 38)->setOffsetX(770)->setOffsetY(680);
$shape->getActiveParagraph()->getAlignment()
->setHorizontal(Alignment::HORIZONTAL_RIGHT)
->setVertical(Alignment::VERTICAL_BASE);
$shape->setAutoFit(RichText::AUTOFIT_NORMAL);
$textRun = $shape->createTextRun('')->getFont()->setSize(18);
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_SLIDENUM))->getPlaceholder()->setIdx(12);
$textRun = $shape->createTextRun('')->getFont()->setSize(10);
$shape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_SLIDENUM));

// Create a shape (drawing)
echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
Expand Down
73 changes: 73 additions & 0 deletions samples/Sample_20_SlideLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

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

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

echo date('H:i:s') . ' Create Footer' . EOL;
$footerTextShape = $slideLayout->createRichTextShape();
$footerTextShape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_FOOTER));

$footerTextShape
->setOffsetX(77)
->setOffsetY(677)
->setWidth(448)
->setHeight(23);

$footerTextRun = $footerTextShape->createTextRun('Footer placeholder');
$footerTextRun->getFont()
->setName('Calibri')
->setSize(9)
->setColor(new Color(Color::COLOR_DARKGREEN))
->setBold(true);

echo date('H:i:s') . ' Create SlideNumber' . EOL;

$numberTextShape = $slideLayout->createRichTextShape();
$numberTextShape->setPlaceHolder(new Placeholder(Placeholder::PH_TYPE_SLIDENUM));

$numberTextShape
->setOffsetX(43)
->setOffsetY(677)
->setWidth(43)
->setHeight(23);

$numberTextRun = $numberTextShape->createTextRun('');
$numberTextRun->getFont()
->setName('Calibri')
->setSize(9)
->setColor(new Color(Color::COLOR_DARKGREEN))
->setBold(true);

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';
}
File renamed without changes.
Loading

0 comments on commit 21b20d2

Please sign in to comment.