Version 0.2.0
PHPPowerPoint is a library written in pure PHP that provides a set of classes to write to different presentation file formats, i.e. OpenXML (.pptx) and OpenDocument (.odp). PHPPowerPoint is an open source project licensed under LGPL.
- Create an in-memory presentation representation
- Set presentation meta data (author, title, description, etc)
- Add slides from scratch or from existing one
- Supports different fonts and font styles
- Supports different formatting, styles, fills, gradients
- Supports hyperlinks and rich-text strings
- Add images with different styles (positioning, rotation, shadow)
- Set printing options (header, footer, page margins, paper size, orientation)
- Output to different file formats: PowerPoint 2007 (.pptx), OpenDocument Presentation (.odp), Serialized Spreadsheet)
- ... and lots of other things!
The following requirements should be met prior to using PHPPowerPoint:
- PHP version 5.2 or higher
- PHP extension php_zip enabled
- PHP extension php_xml enabled
To install and use PHPPowerPoint, copy the contents of the Classes
folder and include PHPPowerPoint.php
somewhere in your code like below.
include_once '/path/to/Classes/PHPPowerPoint.php';
After that, you can use the library by creating a new instance of the class.
$phpPowerPoint = new PHPPowerPoint();
Use getProperties
method to set document properties or metadata like author name and presentation title like below.
$phpPowerPoint = new PHPPowerPoint();
$properties = $phpPowerPoint->getProperties();
$properties->setTitle('My presentation');
Available methods for setting document properties are:
setCategory
setCompany
setCreated
setCreator
setDescription
setKeywords
setLastModifiedBy
setModified
setSubject
setTitle
Slides are pages in a presentation. Slides are stored as a zero based array in PHPPowerPoint
object. Use createSlide
to create a new slide and retrieve the slide for other operation such as creating shapes for that slide.
$slide = $phpPowerPoint->createSlide();
$shape = $slide->createRichTextShape();
Shapes are objects that can be added to a slide. There are five types of shapes that can be used, i.e. rich text, line, chart, drawing, and table. Read the corresponding section of this manual for detail information of each shape.
Every shapes have common properties that you can set by using fluent interface.
width
in pixelsheight
in pixelsoffsetX
in pixelsoffsetY
in pixelsrotation
in degreesfill
see Fillborder
see Bordershadow
see Shadowhyperlink
Example:
$richtext = $slide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
Rich text shapes contain paragraphs of texts. To create a rich text shape, use createRichTextShape
method of slide.
$richtext = $slide->createRichTextShape()
Below are the properties that you can set for a rich text shape.
wrap
autoFit
horizontalOverflow
verticalOverflow
upright
vertical
columns
bottomInset
in pixelsleftInset
in pixelsrightInset
in pixelstopInset
in pixels
Example:
$richtext = $slide->createRichTextShape()
->setWrap(PHPPowerPoint_Shape_RichText::WRAP_SQUARE)
->setBottomInset(600);
Properties that can be set for each paragraphs are as follow.
To create a line, use createLineShape
method of slide.
$line = $slide->createLineShape($fromX, $fromY, $toX, $toY);
To create a chart, use createChartShape
method of slide.
$chart = $slide->createChartShape();
To create a drawing, use createDrawingShape
method of slide.
$drawing = $slide->createDrawingShape();
$drawing->setName('Unique name')
->setDescription('Description of the drawing')
->setPath('/path/to/drawing.filename');
To create a table, use createTableShape
method of slide.
$table = $slide->createTableShape($columns);
Use this style to define fill of a shape as example below.
$shape->getFill()
->setFillType(PHPPowerPoint_Style_Fill::FILL_GRADIENT_LINEAR)
->setRotation(270)
->setStartColor(new PHPPowerPoint_Style_Color('FFCCCCCC'))
->setEndColor(new PHPPowerPoint_Style_Color('FFFFFFFF'));
Properties:
fillType
rotation
startColor
endColor
Use this style to define border of a shape as example below.
$shape->getBorder()
->setLineStyle(PHPPowerPoint_Style_Border::LINE_SINGLE)
->setLineWidth(4)
->getColor()->setARGB('FFC00000');
Properties:
lineWidth
lineStyle
dashStyle
color
Use this style to define shadow of a shape as example below.
$shape->getShadow()
->setVisible(true)
->setDirection(45)
->setDistance(10);
Properties:
visible
blurRadius
distance
direction
alignment
color
alpha
horizontal
vertical
level
indent
marginLeft
marginRight
name
bold
italic
superScript
subScript
underline
strikethrough
color
bulletType
bulletFont
bulletChar
bulletNumericStyle
bulletNumericStartAt
Colors can be applied to different objects, e.g. font or border.
$textRun = $shape->createTextRun('Text');
$textRun->getFont()->setColor(new PHPPowerPoint_Style_Color('C00000'));
Use the IOFactory
object to write resulting presentation to a file.
$writer = PHPPowerPoint_IOFactory::createWriter($phpPowerPoint, $writerName);
$writer->save('/path/to/result.document');
Use PowerPoint2007
for $writerName
.
$writer = PHPPowerPoint_IOFactory::createWriter($phpPowerPoint, 'PowerPoint2007');
$writer->save('/path/to/result.pptx');
Use ODPresentation
for $writerName
.
$writer = PHPPowerPoint_IOFactory::createWriter($phpPowerPoint, 'ODPresentation');
$writer->save('/path/to/result.odp');