<?php
// with Composer
require_once 'vendor/autoload.php';
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\DocumentLayout;
use PhpOffice\PhpPresentation\Slide;
use PhpOffice\PhpPresentation\Slide\Background\Image;
use PhpOffice\PhpPresentation\Style\Fill;
use PhpOffice\PhpPresentation\Shape\Drawing;
use PhpOffice\PhpPresentation\Style\Border;
//新規プレゼンテーション作成
$phpPres = new PhpPresentation();
//ドキュメントのプロパティ設定
$phpPres->getDocumentProperties()
->setCreator('@IPSJ')
->setCompany('一般社団法人情報処理学会')
->setTitle('インタラクション2023表彰状')
->setDescription('インタラクション2023表彰状');
// 印刷用(A4)なら1、16x9なら2を選択
echo "印刷用(A4)なら 1 、クロージング用(16x9)なら 2 を入力してください。\n";
$type = trim(fgets(STDIN));
$outfile = "output表彰状{$type}.pptx";
echo "「{$type}」が入力されました。「{$outfile}」に出力します。\n";
sleep(1);
//A4のサイズはEMUで、self::LAYOUT_A4 => ['cx' => 10692000, 'cy' => 7560000],
// $width = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cx']);
if ($type == "1") {
$phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_A4, false); //false=portrait
require_once 'lib_a4.php';
//マスタースライドに画像を設定
// $oMasterSlide = $phpPres->getAllMasterSlides()[0];
// $oBkgImage = new Image();
// $oBkgImage->setPath('template1.jpg'); //PDFでもよいが、開く時に、修復が必要になる
// $oMasterSlide->setBackground($oBkgImage);
$oLayout = $phpPres->getLayout();
$width = $oLayout->getCX($oLayout::UNIT_PIXEL);
$height = $oLayout->getCY($oLayout::UNIT_PIXEL);
// 印刷するときはスライドマスターと、コンテンツのあいだに、白い矩形をはさんでおくとよいかもしれない
// $cover = $oMasterSlide->createRichTextShape()->setHeight(1123)->setWidth(794)
// ->setOffsetX(0)->setOffsetY(0);
// $cover->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(45)->setStartColor(new Color('FFffffff'))->setEndColor(new Color('FFffffff'));
} else if ($type == "2") {
$phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_SCREEN_16X9, true);
require_once 'lib_16x9.php';
//マスタースライドに画像を設定
$oMasterSlide = $phpPres->getAllMasterSlides()[0];
// $oBkgImage = new Image();
// $oBkgImage->setPath('template1.jpg'); //PDFでもよいが、開く時に、修復が必要になる
$oLayout = $phpPres->getLayout();
$width = $oLayout->getCX($oLayout::UNIT_PIXEL);
$height = $oLayout->getCY($oLayout::UNIT_PIXEL);
$a4width = floor($height / 1.41);
echo "a4width = {$a4width}\n";
$img = new Drawing\File();
$hamidasi = 16; // X方向の画像はみだし量(pixel) Y方向のはみだし量は、これの1.4倍になる
$img->setName('Image File')
->setDescription('Image File')
->setPath('template1.jpg')
->setHeight($height + round($hamidasi*2*1.4))
->setOffsetX(($width - $a4width) / 2 - $hamidasi)
->setOffsetY(round(-$hamidasi*1.4));
$img->getBorder()->setColor(new Color('FFffffff'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE);
$oMasterSlide->addShape($img);
// 紙のまわりの枠線(画像の縁よりも、すこし内側に表示する)
$border = $oMasterSlide->createRichTextShape()
->setHeight($height)
->setWidth($a4width)
->setOffsetX(($width - $a4width) / 2)
->setOffsetY(0);
$border->getFill()->setFillType(Fill::FILL_NONE);
$border->getBorder()->setColor(new Color('FF333333'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE);
// $img の左ボーダーが消えないので、白い矩形を置く
$kesi = $oMasterSlide->createRichTextShape()
->setHeight($height + $hamidasi*2)
->setWidth(20)
->setOffsetX(($width - $a4width) / 2 - $hamidasi -10)
->setOffsetY(-$hamidasi);
$kesi->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color('FFffffff'))->setEndColor(new Color('FFffffff'));
// $kesi->getBorder()->setColor(new Color('FFffffff'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE);
// $oMasterSlide->setBackground($oBkgImage);
}
// $width = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cx']);
// $height = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cy']);
echo "width {$width} pixels x height {$height} pixels \n";
///////////////////////////////////////////////////////////
$ary = [
"title" => "PHPPresentationを利用した表彰状の作成",
"authors" => ["苗字 名前"],
];
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
array_push($ary["authors"], "苗字 名前");
addHSJ($phpPres, $ary);
$phpPres->removeSlideByIndex(0); // 最初のスライドを削除する
$oWriterPPTX = IOFactory::createWriter($phpPres, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/{$outfile}");
// $oWriterODP = IOFactory::createWriter($phpPres, 'ODPresentation');
// $oWriterODP->save(__DIR__ . "/sample.odp");