<?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;
/**
* add Rich Text Shape テキストボックスの追加
* A4 Paper size by UNIT_PIXEL = 794 x 1123
*/
function addRTShape(
PhpPresentation $pres,
Slide $slide,
int $intw, // 幅のピクセル数
float $ypercent, // ボックスのY座標を、パーセントで。(50だとちょうど半分、中央の高さ)
string $mes,
int $size,
string $h_alignment = Alignment::HORIZONTAL_CENTER,
string $v_alignment = Alignment::VERTICAL_AUTO
) {
$oLayout = $pres->getLayout();
// $intw = 600;//(int)( ($oLayout->getCX($oLayout::UNIT_PIXEL) * 0.8));
$inth = 300; // 固定値 (int)($oLayout->getCY($oLayout::UNIT_PIXEL));
$intoffx = (int)(($oLayout->getCX($oLayout::UNIT_PIXEL) - $intw) / 2);
$intoffy = (int)(($oLayout->getCY($oLayout::UNIT_PIXEL) * $ypercent / 100));
// echo $oLayout->getCX($oLayout::UNIT_PIXEL) . " " . $intw . " " . $inth . " " . $intoffx . " " . $intoffy . "\n";
$shape2 = $slide->createRichTextShape()
->setWidth($intw) // 794px
->setHeight($inth) // 1123px
->setOffsetX($intoffx)
->setOffsetY($intoffy);
$shape2->getActiveParagraph()
->getAlignment()
->setHorizontal($h_alignment)
->setVertical($v_alignment);
$textRun2 = $shape2->createTextRun($mes);
$textRun2->getFont()
->setName('ヒラギノ明朝 Pro W3') // TODO: Windowsの場合は変更が必要かも
->setBold(false)
->setSize($size)
->setColor(new Color('FF000000')); // 最初のFFは不透明度。そのあとRRGGBB
$shape2->getActiveParagraph()->setLineSpacing(120); // 行間(Line Spacing)。100だとぴったり。150だと1.5倍
}
/**
* $ary['title']
* $ary['authors] = [ "著者1" , "著者2", ...]
*/
function addHSJ(PhpPresentation $pres, $ary)
{
$pres->createSlide();
$pres->setActiveSlideIndex($pres->getSlideCount() - 1);
$slide = $pres->getActiveSlide();
addRTShape($pres, $slide, 600, 15, "インタラクション2023", 23);
addRTShape($pres, $slide, 600, 20, "インタラクティブ発表賞(PC推薦)", 26);
$authors = ""; //著者名
$aindex = 0;
if (count($ary['authors']) % 2 == 1) { //著者人数が奇数
$authors .= $ary['authors'][0] . "殿\r\n"; //まず、筆頭著者を書く
$aindex = 1;
}
for ($i = $aindex; $i < count($ary['authors']); $i += 2) {
$authors .= $ary['authors'][$i] . "殿 "; // 残りを2人ずつ書く
$authors .= $ary['authors'][$i + 1] . "殿";
$authors .= "\r\n";
}
$additionalline = 0;
if (count($ary["authors"]) > 2) { //著者の行が増えたことを考慮し、本文をすこし下げる
$additionalline = floor((count($ary["authors"]) - 1) / 2);
// echo "additional " . $additionalline . "\n";
}
addRTShape($pres, $slide, 600, 18.5 + $additionalline * 1.2, $authors, 24, Alignment::HORIZONTAL_CENTER, Alignment::VERTICAL_CENTER);
addRTShape($pres, $slide, 576, 36.5 + $additionalline * 2, "貴殿が本学会シンポジウム インタラクション2023において発表された" .
"「{$ary['title']}」" .
"は本シンポジウムプログラム委員会にて厳正な審査を行った結果新たなインタラクション研究の方向性を示すものであり" .
"今後の情報処理分野の発展に寄与する優秀な発表として認められました\r\nよってここに表彰いたします", 18, Alignment::HORIZONTAL_GENERAL);
addRTShape($pres, $slide, 520, 67 + $additionalline , "令和5年3月10日\r\n" .
"一般社団法人 情報処理学会\r\n" .
"インタラクション2023\r\n" .
"大会委員長 寺田 努 \r\n" .
"プログラム委員長 竹川 佳成\r\n" .
"インタラクティブ発表委員長 生田 泰章\r\n", 18, Alignment::HORIZONTAL_RIGHT);
return $slide; //あとで使うことがなければ、必要ない
}
//新規プレゼンテーション作成
$phpPres = new PhpPresentation();
// $phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_SCREEN_16X9);
$phpPres->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_A4, false); //false=portrait
//A4のサイズはEMUで、self::LAYOUT_A4 => ['cx' => 10692000, 'cy' => 7560000],
// $width = Drawing::emuToPixels(DocumentLayout::LAYOUT_A4['cx']);
//ドキュメントのプロパティ設定
$phpPres->getDocumentProperties()
->setCreator('@IPSJ')
->setCompany('一般社団法人情報処理学会')
->setTitle('インタラクション2023表彰状')
->setDescription('インタラクション2023表彰状');
///////////////////////////////////////////////////////////
$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); // 最初のスライドを削除する
//マスタースライドに画像を設定
$oMasterSlide = $phpPres->getAllMasterSlides()[0];
$oBkgImage = new Image();
$oBkgImage->setPath('template3.png'); //PDFでもよいが、開く時に、修復が必要になる
$oMasterSlide->setBackground($oBkgImage);
// 印刷するときはスライドマスターと、コンテンツのあいだに、白い矩形をはさんでおくとよいかもしれない
// $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'));
$oWriterPPTX = IOFactory::createWriter($phpPres, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/output表彰状.pptx");
// $oWriterODP = IOFactory::createWriter($phpPres, 'ODPresentation');
// $oWriterODP->save(__DIR__ . "/sample.odp");