Source for file PowerPoint2007.php
Documentation is available at PowerPoint2007.php
* Copyright (c) 2009 - 2010 PHPPowerPoint
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @category PHPPowerPoint
* @package PHPPowerPoint_Writer_PowerPoint2007
* @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.1.0, 2009-04-27
require_once 'PHPPowerPoint.php';
/** PHPPowerPoint_HashTable */
require_once 'PHPPowerPoint/HashTable.php';
/** PHPPowerPoint_IComparable */
require_once 'PHPPowerPoint/IComparable.php';
/** PHPPowerPoint_Slide */
require_once 'PHPPowerPoint/Slide.php';
/** PHPPowerPoint_IWriter */
require_once 'PHPPowerPoint/Writer/IWriter.php';
/** PHPPowerPoint_Shared_XMLWriter */
require_once 'PHPPowerPoint/Shared/XMLWriter.php';
/** PHPPowerPoint_Writer_PowerPoint2007_WriterPart */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/WriterPart.php';
/** PHPPowerPoint_Writer_PowerPoint2007_ContentTypes */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/ContentTypes.php';
/** PHPPowerPoint_Writer_PowerPoint2007_DocProps */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/DocProps.php';
/** PHPPowerPoint_Writer_PowerPoint2007_Rels */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/Rels.php';
/** PHPPowerPoint_Writer_PowerPoint2007_Theme */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/Theme.php';
/** PHPPowerPoint_Writer_PowerPoint2007_Presentation */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/Presentation.php';
/** PHPPowerPoint_Writer_PowerPoint2007_Slide */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/Slide.php';
/** PHPPowerPoint_Writer_PowerPoint2007_Drawing */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/Drawing.php';
/** PHPPowerPoint_Writer_PowerPoint2007_LayoutPack */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/LayoutPack.php';
/** PHPPowerPoint_Writer_PowerPoint2007_LayoutPack_Default */
require_once 'PHPPowerPoint/Writer/PowerPoint2007/LayoutPack/Default.php';
* PHPPowerPoint_Writer_PowerPoint2007
* @category PHPPowerPoint
* @package PHPPowerPoint_Writer_PowerPoint2007
* @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
* Office2003 compatibility
* @var PHPPowerPoint_Writer_PowerPoint2007_WriterPart[]
* Private unique PHPPowerPoint_Worksheet_BaseDrawing HashTable
* @var PHPPowerPoint_HashTable
* Use disk caching where possible?
* @var PHPPowerPoint_Writer_PowerPoint2007_LayoutPack
* Create a new PHPPowerPoint_Writer_PowerPoint2007
* @param PHPPowerPoint $pPHPPowerPoint
public function __construct(PHPPowerPoint $pPHPPowerPoint = null)
// Set up disk caching location
// Initialise writer parts
$writer->setParentWriter($this);
// Set HashTable variables
* @param string $pPartName Writer part name
* @return PHPPowerPoint_Writer_PowerPoint2007_WriterPart
* Save PHPPowerPoint to file
* @param string $pFileName
public function save($pFilename = null)
// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
$pFilename = @tempnam('./', 'phppttmp');
$pFilename = $originalFilename;
// Create drawing dictionary
// Create new ZIP file and open it for writing
$objZip = new ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
// Add [Content_Types].xml to ZIP file
// Add relationships to ZIP file
$objZip->addFromString('ppt/_rels/presentation.xml.rels', $this->getWriterPart('Rels')->writePresentationRelationships($this->_presentation));
// Add document properties to ZIP file
// Add slide master to ZIP file
$objZip->addFromString('ppt/slideMasters/_rels/slideMaster1.xml.rels', $this->getWriterPart('Rels')->writeSlideMasterRelationships());
$objZip->addFromString('ppt/slideMasters/slideMaster1.xml', $masterSlide['body']);
// Add slide layouts to ZIP file
for ($i = 0; $i < count($slideLayouts); ++ $i) {
$objZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeSlideLayoutRelationships());
$objZip->addFromString('ppt/slideLayouts/slideLayout' . ($i + 1) . '.xml', $slideLayouts[$i]['body']);
// Add presentation to ZIP file
// Add slides (drawings, ...)
$objZip->addFromString('ppt/slides/slide' . ($i + 1) . '.xml', $this->getWriterPart('Slide')->writeSlide($this->_presentation->getSlide($i)));
// Add slide relationships (drawings, ...)
$objZip->addFromString('ppt/slides/_rels/slide' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeSlideRelationships($this->_presentation->getSlide($i), ($i + 1)));
if (strpos($imagePath, 'zip://') !== false) {
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$imageZip = new ZipArchive();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
if ($objZip->close() === false) {
throw new Exception("Could not close zip file $pFilename.");
// 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.");
throw new Exception("PHPPowerPoint object unassigned.");
* Get PHPPowerPoint object
throw new Exception("No PHPPowerPoint assigned.");
* Get PHPPowerPoint object
* @param PHPPowerPoint $pPHPPowerPoint PHPPowerPoint object
* Get PHPPowerPoint_Worksheet_BaseDrawing HashTable
* @return PHPPowerPoint_HashTable
* Get Office2003 compatibility
* Set Pre-Calculate Formulas
* @param boolean $pValue Office2003 compatibility?
* Get use disk caching where possible?
* Set use disk caching where possible?
* @param string $pDirectory Disk caching directory
* @throws Exception Exception when directory does not exist
throw new Exception("Directory does not exist: $pDirectory");
* Get disk caching directory
* @return PHPPowerPoint_Writer_PowerPoint2007_LayoutPack
* @param PHPPowerPoint_Writer_PowerPoint2007_LayoutPack $pValue
public function setLayoutPack(PHPPowerPoint_Writer_PowerPoint2007_LayoutPack $pValue = null) {
|