PhpOffice\PhpPresentation\Writer\PowerPoint2007::save PHP Method

save() public method

Save PhpPresentation to file
public save ( string $pFilename )
$pFilename string
    public function save($pFilename)
    {
        if (empty($pFilename)) {
            throw new \Exception("Filename is empty");
        }
        $oPresentation = $this->getPhpPresentation();
        // If $pFilename is php://output or php://stdout, make it a temporary file...
        $originalFilename = $pFilename;
        if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
            $pFilename = @tempnam('./', 'phppttmp');
            if ($pFilename == '') {
                $pFilename = $originalFilename;
            }
        }
        // Create drawing dictionary
        $this->getDrawingHashTable()->addFromSource($this->allDrawings());
        $oZip = $this->getZipAdapter();
        $oZip->open($pFilename);
        $oDir = new DirectoryIterator(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PowerPoint2007');
        foreach ($oDir as $oFile) {
            if (!$oFile->isFile()) {
                continue;
            }
            $class = __NAMESPACE__ . '\\PowerPoint2007\\' . $oFile->getBasename('.php');
            $o = new \ReflectionClass($class);
            if ($o->isAbstract() || !$o->isSubclassOf('PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007\\AbstractDecoratorWriter')) {
                continue;
            }
            $arrayFiles[$oFile->getBasename('.php')] = $o;
        }
        ksort($arrayFiles);
        foreach ($arrayFiles as $o) {
            $oService = $o->newInstance();
            $oService->setZip($oZip);
            $oService->setPresentation($oPresentation);
            $oService->setDrawingHashTable($this->getDrawingHashTable());
            $oZip = $oService->render();
            unset($oService);
        }
        // Close file
        $oZip->close();
        // If a temporary file was used, copy it to the correct file stream
        if ($originalFilename != $pFilename) {
            if (copy($pFilename, $originalFilename) === false) {
                throw new \Exception("Could not copy temporary zip file {$pFilename} to {$originalFilename}.");
            }
            if (@unlink($pFilename) === false) {
                throw new \Exception('The file ' . $pFilename . ' could not be removed.');
            }
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Test save
  */
 public function testSave()
 {
     $filename = tempnam(sys_get_temp_dir(), 'PhpPresentation');
     $imageFile = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/images/PhpPresentationLogo.png';
     $oPhpPresentation = new PhpPresentation();
     $slide = $oPhpPresentation->getActiveSlide();
     $slide->createRichTextShape();
     $slide->createLineShape(10, 10, 10, 10);
     $slide->createChartShape()->getPlotArea()->setType(new \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar3D());
     $slide->createDrawingShape()->setName('Drawing')->setPath($imageFile);
     $slide->createTableShape()->createRow();
     $object = new PowerPoint2007($oPhpPresentation);
     $object->save($filename);
     $this->assertTrue(file_exists($filename));
     unlink($filename);
 }
All Usage Examples Of PhpOffice\PhpPresentation\Writer\PowerPoint2007::save