<?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;
$year = date('Y');
//新規プレゼンテーション作成
$phpPres = new PhpPresentation();
//ドキュメントのプロパティ設定
$phpPres->getDocumentProperties()
->setCreator('@IPSJ')
->setCompany('一般社団法人情報処理学会')
->setTitle("インタラクション{$year}表彰状")
->setDescription("インタラクション{$year}表彰状");
// 印刷用(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";
///////////////////////////////////////////////////////////
// 差し込み
$baseary["year"] = $year;
$baseary["date"] = "令和7年3月2日";
$baseary["awardname"] = "優秀論文賞";
$baseary["eventname"] = "インタラクション{$baseary['year']}";
$baseary["content"] = "貴殿が情報処理学会{$baseary['eventname']}にて発表された「[:TITLE:]」" .
"は特に優秀な論文であり論文賞を授与するにふさわしいものであると認めます。\r\nよってここに表彰いたします。";
$baseary["presenter"] = $baseary["date"] . "\r\n" .
"一般社団法人 情報処理学会\r\n" .
"インタラクション{$year}"."\r\n" .
"大会委員長 三武 裕玄\r\n" .
"プログラム委員長 伊藤 雄一\r\n" .
"インタラクティブ発表委員長 橋本 直 ";
/**
* TODO: 毎年変わるダウンロードキーをURL末尾に設定してください。
*/
$url = "https://confmanex.interaction-ipsj.org/awards/json_booth_title_author/xxxxxx";
if (strpos($url, "xxxxxx") > 0) {
echo "ダウンロードキーを入力してください。(またはaward.php 126行目付近で設定)\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); // JSON内容を確認するとき
$awards = [
"優秀論文賞" => "貴殿が情報処理学会{$baseary['eventname']}にて発表された「[:TITLE:]」" .
"は本シンポジウムプログラム委員会にて厳正な審査を行った結果新たなインタラクション研究の方向性を示すものであり" .
"今後の情報処理分野の発展に寄与する優秀な発表として認められました\r\nよってここに表彰いたします",
"インタラクティブ発表賞(PC推薦)" => "貴殿が本学会シンポジウム インタラクション{$year}において発表された" .
"「[:TITLE:]」" .
"は本シンポジウムプログラム委員会にて厳正な審査を行った結果新たなインタラクション研究の方向性を示すものであり" .
"今後の情報処理分野の発展に寄与する優秀な発表として認められました\r\nよってここに表彰いたします",
];
/**
* TODO: ここで、受賞者の論文のブース、発表番号を 半角スペース区切り で入れてください。
* 空文字列にすると、すべての論文を出力します。
*/
$winners = [
"優秀論文賞" => "01 03 05", //"1-1 1-2",
"インタラクティブ発表賞(PC推薦)" => "1A01 2A01", // "1A01 2A01", //"1-3",
];
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); // 最初のスライドを削除する
// define("YEAR",2025);
// define("AWARDNAME",);
// define("DATE",);
// $json = file_get_contents($url);
// $obj = json_decode($json, true);
// // var_dump($obj); // 確認表示
// // 全部出力する場合
// // foreach($obj as $booth=>$ary){
// // addHSJ($phpPres, $ary);
// // }
// // 一部の【ブース番号】(not paper id)だけを出力する場合 半角スペース区切り
// $booth_list = "1 2 3 4 5 ";
// $booth_list_ary = explode(" ", trim($booth_list));
// foreach ($booth_list_ary as $b) {
// $ary = $obj[$b];
// addHSJ($phpPres, $ary);
// }
// $ary = [
// "title" => "PHPPresentationを利用した表彰状の作成",
// "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");