<?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"; /////////////////////////////////////////////////////////// // 投稿システムからの読み込み(採択分のみ) // https://confman.interaction-ipsj.org/awards/json_booth_title_author // define("YEAR", 2023); // define("AWARDNAME", "優秀論文賞"); // define("DATE", "令和5年8月20日"); // 差し込み $baseary["year"] = 2023; $baseary["date"] = "令和5年8月20日"; $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"; $url = "https://sss.istlab.info/awards/json_booth_title_author/oimo"; $json = file_get_contents($url); $obj = json_decode($json, true); // var_dump($obj); // 確認表示 // 一部の【ブース番号】(not paper id)だけを出力する場合 半角スペース区切り // $booth_list = "1 2 3 4 5 "; $booth_list = ""; 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); } } // $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");