Skip to content

Instantly share code, notes, and snippets.

@nawarian
Created March 14, 2020 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nawarian/da1527d8057d74c23ff1c450bbf4d09e to your computer and use it in GitHub Desktop.
Save nawarian/da1527d8057d74c23ff1c450bbf4d09e to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace PPTeizor;
use DateTimeImmutable;
use PhpOffice\Common\Adapter\Zip\ZipInterface;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
use PHPUnit\Framework\TestCase;
class TestarGerarOPPTTest extends TestCase
{
public function testQueTestou(): void
{
$data = new DateTimeImmutable('2020-01-01');
$imagem = __DIR__ . '/../var/examples/img.jpg';
$arquivos = array_fill(0, 700, [$data, $imagem]);
// 0 -> data, 1 -> imagem
$objPHPPowerPoint = new PhpPresentation();
$start = microtime(true);
foreach ($arquivos as $pos => $arquivo) {
list ($data, $imagem) = $arquivo;
$currentSlide = $objPHPPowerPoint->createSlide();
$shape = $currentSlide->createDrawingShape();
$shape->setName("img-{$pos}")
->setPath($imagem)
->setWidthAndHeight(756, 1092)
->setOffsetX(0)
->setOffsetY(0);
}
var_dump(
'Generating slides: ' . (microtime(true) - $start)
);
// $oWriterPPTX = new PowerPoint2007($objPHPPowerPoint);
$oWriterPPTX = new class($objPHPPowerPoint) extends PowerPoint2007 {
public function save($pFilename)
{
$start = microtime(true);
// Create drawing dictionary
$this->getDrawingHashTable()->addFromSource($this->allDrawings());
$oZip = $this->getZipAdapter();
// $oZip = new class implements ZipInterface {
// public function addFromString($path, $contents): void
// {}
//
// public function open($filename)
// {}
//
// public function close()
// {}
// };
$oZip->open($pFilename);
$classes = [
PowerPoint2007\CommentAuthors::class,
PowerPoint2007\ContentTypes::class,
PowerPoint2007\DocPropsApp::class,
PowerPoint2007\DocPropsCore::class,
PowerPoint2007\DocPropsCustom::class,
PowerPoint2007\DocPropsThumbnail::class,
PowerPoint2007\PptCharts::class,
PowerPoint2007\PptComments::class,
PowerPoint2007\PptMedia::class,
PowerPoint2007\PptPresProps::class,
PowerPoint2007\PptPresentation::class,
PowerPoint2007\PptSlideLayouts::class,
PowerPoint2007\PptSlideMasters::class,
PowerPoint2007\PptSlides::class,
PowerPoint2007\PptTableProps::class,
PowerPoint2007\PptTheme::class,
PowerPoint2007\PptViewProps::class,
PowerPoint2007\Relationships::class,
];
foreach ($classes as $class) {
$oService = new $class();
$oService->setZip($oZip);
$oService->setPresentation($this->getPhpPresentation());
$oService->setDrawingHashTable($this->getDrawingHashTable());
$oZip = $oService->render();
unset($oService);
}
// Close file
$oZip->close();
var_dump(
microtime(true) - $start
);
die;
}
};
$oWriterPPTX->save(__DIR__ . '/../var/out.pptx');
die;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment