<?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('情報教育シンポジウム2025表彰状')
->setDescription('情報教育シンポジウム2025表彰状');
// 印刷用(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.png')
->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);
}
echo "width {$width} pixels x height {$height} pixels \n";
///////////////////////////////////////////////////////////
// 差し込み
$baseary["year"] = 2025;
$baseary["date"] = "令和7年8月21日";
$baseary["awardname"] = "優秀論文賞";
$baseary["eventname"] = "情報教育シンポジウム{$baseary['year']}";
$baseary["content"] = "貴殿が情報処理学会{$baseary['eventname']}にて発表された「[:TITLE:]」" .
"は特に優秀な論文であり論文賞を授与するにふさわしいものであると認めます。\r\nよってここに表彰いたします。";
$baseary["presenter"] = $baseary["date"] . "\r\n" .
"一般社団法人 情報処理学会\r\n" .
"情報教育シンポジウム{$baseary['year']}\r\n" .
"プログラム委員長 隅谷 孝洋\r\n" .
"実行委員長 鈴木 大助\r\n" .
"大会委員長 林 浩一\r\n";
/**
* TODO: 毎年変わるダウンロードキーをdownload_key.txt に設定してください。
*/
$filename = "download_key.txt";
$dlkey = trim(file_get_contents($filename));
$url = "https://sss25.istlab.info/awards/json_booth_title_author/${dlkey}";
if (strpos($url, "xxxxxx") > 0) {
echo "ダウンロードキーを入力してください。(またはaward.php 123行目付近で設定)\n";
$type = trim(fgets(STDIN));
echo "「{$type}」が入力されました。\n";
$url = str_replace("xxxxxx",$type, $url);
sleep(1);
}
$json = file_get_contents($url);
$obj = json_decode($json, true);
// var_dump($obj); // 確認表示
$awards = [
"優秀論文賞" => "貴殿が情報処理学会{$baseary['eventname']}にて発表された「hoge」は特に優秀な論文であり、情報教育の発展に貢献することを認めここに表彰いたします。",
"優秀発表賞" => "貴殿が情報処理学会{$baseary['eventname']}にて発表された「hoge」は特に優秀な発表であり、情報教育の発展に貢献することを認めここに表彰いたします。",
"デモ・ポスター賞" => "貴殿が情報処理学会{$baseary['eventname']}にて発表された「hoge」は特に優秀なデモ・ポスターであり、情報教育の発展に貢献することを認めここに表彰いたします。",
"学生奨励賞" => "貴殿が情報処理学会{$baseary['eventname']}にて発表された「hoge」は特に優秀な学生発表であることを認めここに表彰いたします。"
];
/**
* TODO: ここで、受賞者の論文のブース、発表番号を 半角スペース区切り で入れてください。
* 空文字列にすると、すべての論文を出力します。
*/
$winners = [
"優秀論文賞" => "", //"1-1 1-2",
"優秀発表賞" => "", //"1-3",
"デモ・ポスター賞" => "", //"P-1",
"学生奨励賞" => "", //"7-1",
];
foreach ($awards as $award => $body) {
$baseary["awardname"] = $award; // 〜〜賞
$baseary["content"] = str_replace("hoge", "[:TITLE:]", $body); // 貴殿が... (hogeを[:TITLE:]に差し替える)
$booth_list = $winners[$award];
if (strlen($booth_list) > 1) {
$booth_list_ary = explode(" ", trim($booth_list));
foreach ($booth_list_ary as $b) {
$ary = $obj[$b];
$ary = array_merge($ary, $baseary);
addHSJ($phpPres, $ary);
}
} else {
// 全部出力する場合
foreach ($obj as $booth => $ary) {
$ary = array_merge($ary, $baseary);
addHSJ($phpPres, $ary);
}
}
echo $award." を出力しました。\n";
}
$phpPres->removeSlideByIndex(0); // 最初のスライドを削除する
$oWriterPPTX = IOFactory::createWriter($phpPres, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/{$outfile}");
// $oWriterODP = IOFactory::createWriter($phpPres, 'ODPresentation');
// $oWriterODP->save(__DIR__ . "/sample.odp");