Top Banner
PhpPowerpoint Documentation Release 0.12.0 The PhpPowerpoint Team September 24, 2014
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • PhpPowerpoint DocumentationRelease 0.12.0

    The PhpPowerpoint Team

    September 24, 2014

  • Contents

    1 Introduction 31.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 File formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    2 Installing/configuring 52.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Using samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    3 General usage 73.1 Basic example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Document information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    4 Slides 9

    5 Shapes 115.1 Rich text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.2 Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.3 Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.4 Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.5 Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    6 Styles 136.1 Fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.2 Border . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.3 Shadow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136.4 Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.5 Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.6 Bullet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.7 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    7 Writers & readers 157.1 OOXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157.2 OpenDocument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167.3 HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177.4 PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    8 Recipes 19

    i

  • 8.1 Title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    9 Frequently asked questions 219.1 Is this the same with PHPPowerPoint that I found in CodePlex? . . . . . . . . . . . . . . . . . . . . 219.2 Ive been running PHPPowerPoint from CodePlex flawlessly, but I cant use the latest PHPPowerPoint

    from GitHub. Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    10 Credits 23

    11 References 2511.1 OpenXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2511.2 OpenDocument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2511.3 PowerPoint 97 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    12 Indices and tables 27

    ii

  • PhpPowerpoint Documentation, Release 0.12.0

    PHPPowerPoint is a library written in pure PHP that provides a set of classes to write to different presentation fileformats, i.e. OpenXML (.pptx) and OpenDocument (.odp). PHPPowerPoint is an open source project licensed underLGPL.

    Contents 1

  • PhpPowerpoint Documentation, Release 0.12.0

    2 Contents

  • CHAPTER 1

    Introduction

    PHPPowerPoint is a library written in pure PHP that provides a set of classes to write to different presentation fileformats, i.e. Microsoft Office Open XML (.pptx) and OASIS OpenDocument Format for Office Applications (.odp).

    PHPPowerPoint is an open source project licensed under the terms of LGPL version 3. PHPPowerPoint is aimed tobe a high quality software product by incorporating continuous integration and unit testing. You can learn more aboutPHPPowerPoint by reading this Developers Documentation and the API Documentation.

    1.1 Features

    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), SerializedSpreadsheet)

    ... and lots of other things!

    1.2 File formats

    Below are the supported features for each file formats.

    3

  • PhpPowerpoint Documentation, Release 0.12.0

    1.2.1 Writers

    Features PPTX ODP HTML PDFDocument Properties Standard

    CustomElement Shape Image

    HyperlinkLineMemoryImageRichTextTableText

    Charts Bar3DLinePie3DScatter

    1.2.2 Readers

    Features PPTX ODP HTML PDF PPTDocument Properties Standard

    CustomElement Shape Image

    HyperlinkRichTextTableText

    Charts Bar3DLinePie3DScatter

    1.3 Contributing

    We welcome everyone to contribute to PHPPowerPoint. Below are some of the things that you can do to contribute:

    Read our contributing guide

    Fork us and request a pull to the develop branch

    Submit bug reports or feature requests to GitHub

    Follow @PHPOffice on Twitter

    4 Chapter 1. Introduction

  • CHAPTER 2

    Installing/configuring

    2.1 Requirements

    Mandatory:

    PHP 5.3+

    PHP Zip extension

    PHP XML Parser extension

    Optional PHP extensions:

    XMLWriter

    2.2 Installation

    There are two ways to install PHPPowerPoint, i.e. via Composer or manually by downloading the library.

    2.2.1 Using Composer

    To install via Composer, add the following lines to your composer.json:

    {"require": {

    "phpoffice/phppowerpoint": "dev-master"}

    }

    2.2.2 Manual install

    To install manually, download PHPPowerPoint package from github. Extract the package and put the contents toyour machine. To use the library, include src/PhpPowerpoint/Autoloader.php in your script and invokeAutoloader::register.

    require_once /path/to/src/PhpPowerpoint/Autoloader.php;\PhpOffice\PhpPowerpoint\Autoloader::register();

    5

  • PhpPowerpoint Documentation, Release 0.12.0

    2.3 Using samples

    After installation, you can browse and use the samples that weve provided, either by command line or using browser.If you can access your PHPPowerPoint library folder using browser, point your browser to the samples folder, e.g.http://localhost/PhpPowerpoint/samples/.

    6 Chapter 2. Installing/configuring

  • CHAPTER 3

    General usage

    3.1 Basic example

    The following is a basic example of the PHPPowerPoint library. More examples are provided in the samples folder.

    require_once src/PhpPowerpoint/Autoloader.php;\PhpOffice\PhpPowerpoint\Autoloader::register();

    $objPHPPowerPoint = new PhpPowerpoint();

    // Create slide$currentSlide = $objPHPPowerPoint->getActiveSlide();

    // Create a shape (drawing)$shape = $currentSlide->createDrawingShape();$shape->setName(PHPPowerPoint logo)

    ->setDescription(PHPPowerPoint logo)->setPath(./resources/phppowerpoint_logo.gif)->setHeight(36)->setOffsetX(10)->setOffsetY(10);

    $shape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);

    // Create a shape (text)$shape = $currentSlide->createRichTextShape()

    ->setHeight(300)->setWidth(600)->setOffsetX(170)->setOffsetY(180);

    $shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );$textRun = $shape->createTextRun(Thank you for using PHPPowerPoint!);$textRun->getFont()->setBold(true)

    ->setSize(60)->setColor( new Color( FFE06B20 ) );

    $oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, PowerPoint2007);$oWriterPPTX->save(__DIR__ . "/sample.pptx");$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, ODPresentation);$oWriterODP->save(__DIR__ . "/sample.odp");

    7

  • PhpPowerpoint Documentation, Release 0.12.0

    3.2 Document information

    You can set the document information such as title, creator, and company name. Use the following functions:

    $properties = $phpPowerpoint->getProperties();$properties->setCreator(My name);$properties->setCompany(My factory);$properties->setTitle(My title);$properties->setDescription(My description);$properties->setCategory(My category);$properties->setLastModifiedBy(My name);$properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));$properties->setSubject(My subject);$properties->setKeywords(my, key, word);

    8 Chapter 3. General usage

  • CHAPTER 4

    Slides

    Slides are pages in a presentation. Slides are stored as a zero based array in PHPPowerPoint object. UsecreateSlide to create a new slide and retrieve the slide for other operation such as creating shapes for that slide.

    9

  • PhpPowerpoint Documentation, Release 0.12.0

    10 Chapter 4. Slides

  • CHAPTER 5

    Shapes

    Shapes are objects that can be added to a slide. There are five types of shapes that can be used, i.e. [rich text](#rich-text), [line](#line), [chart](#chart), [drawing](#drawing), and [table](#table). Read the corresponding section of thismanual for detail information of each shape.

    Every shapes have common properties that you can set by using fluent interface.

    width in pixels

    height in pixels

    offsetX in pixels

    offsetY in pixels

    rotation in degrees

    fill see [Fill](#fill)

    border see [Border](#border)

    shadow see [Shadow](#shadow)

    hyperlink

    Example:

    5.1 Rich text

    Rich text shapes contain paragraphs of texts. To create a rich text shape, use createRichTextShape method ofslide.

    Below are the properties that you can set for a rich text shape.

    wrap

    autoFit

    horizontalOverflow

    verticalOverflow

    upright

    vertical

    columns

    bottomInset in pixels

    11

  • PhpPowerpoint Documentation, Release 0.12.0

    leftInset in pixels

    rightInset in pixels

    topInset in pixels

    autoShrinkHorizontal (boolean)

    autoShrinkVertical (boolean)

    Properties that can be set for each paragraphs are as follow.

    alignment see [Alignment](#alignment)

    font see [Font](#font)

    bulletStyle see [Bullet](#bullet)

    5.2 Line

    To create a line, use createLineShape method of slide.

    5.3 Chart

    To create a chart, use createChartShape method of slide.

    5.4 Drawing

    To create a drawing, use createDrawingShape method of slide.

    5.5 Drawing

    To create a table, use createTableShape method of slide.

    12 Chapter 5. Shapes

  • CHAPTER 6

    Styles

    6.1 Fill

    Use this style to define fill of a shape as example below.

    Properties:

    fillType

    rotation

    startColor

    endColor

    6.2 Border

    Use this style to define border of a shape as example below.

    Properties:

    lineWidth

    lineStyle

    dashStyle

    color

    6.3 Shadow

    Use this style to define shadow of a shape as example below.

    Properties:

    visible

    blurRadius

    distance

    direction

    alignment

    13

  • PhpPowerpoint Documentation, Release 0.12.0

    color

    alpha

    6.4 Alignment

    horizontal

    vertical

    level

    indent

    marginLeft

    marginRight

    6.5 Font

    name

    bold

    italic

    superScript

    subScript

    underline

    strikethrough

    color

    6.6 Bullet

    bulletType

    bulletFont

    bulletChar

    bulletNumericStyle

    bulletNumericStartAt

    6.7 Color

    Colors can be applied to different objects, e.g. font or border.

    14 Chapter 6. Styles

  • CHAPTER 7

    Writers & readers

    7.1 OOXML

    The package of OOXML document consists of the following files.

    _rels/

    .rels

    docProps/

    app.xml

    core.xml

    custom.xml

    word/

    rels/

    * document.rels.xml

    media/

    theme/

    * theme1.xml

    document.xml

    fontTable.xml

    numbering.xml

    settings.xml

    styles.xml

    webSettings.xml

    [Content_Types].xml

    15

  • PhpPowerpoint Documentation, Release 0.12.0

    7.2 OpenDocument

    7.2.1 Package

    The package of OpenDocument document consists of the following files.

    META-INF/

    manifest.xml

    Pictures/

    content.xml

    meta.xml

    styles.xml

    7.2.2 content.xml

    The structure of content.xml is described below.

    office:document-content

    office:font-facedecls

    office:automatic-styles

    office:body

    * office:text

    draw:*

    office:forms

    table:table

    text:list

    text:numbered-paragraph

    text:p

    text:table-of-contents

    text:section

    * office:chart

    * office:image

    * office:drawing

    7.2.3 styles.xml

    The structure of styles.xml is described below.

    office:document-styles

    office:styles

    office:automatic-styles

    16 Chapter 7. Writers & readers

  • PhpPowerpoint Documentation, Release 0.12.0

    office:master-styles

    * office:master-page

    7.3 HTML

    To be completed.

    7.4 PDF

    To be completed.

    7.3. HTML 17

  • PhpPowerpoint Documentation, Release 0.12.0

    18 Chapter 7. Writers & readers

  • CHAPTER 8

    Recipes

    8.1 Title

    Recipe Text

    $content;

    19

  • PhpPowerpoint Documentation, Release 0.12.0

    20 Chapter 8. Recipes

  • CHAPTER 9

    Frequently asked questions

    9.1 Is this the same with PHPPowerPoint that I found in CodePlex?

    No. This one is much better with tons of new features that you cant find in PHPPowerPoint 0.1. The development inCodePlex is halted and switched to GitHub to allow more participation from the crowd. The more the merrier, right?

    9.2 Ive been running PHPPowerPoint from CodePlex flawlessly, but Icant use the latest PHPPowerPoint from GitHub. Why?

    PHPPowerPoint requires PHP 5.3+ since 0.2, while PHPPowerPoint 0.1 from CodePlex can run with PHP 5.2. Theresa lot of new features that we can get from PHP 5.3 and its been around since 2014! You should upgrade your PHPversion to use PHPPowerPoint 0.2+.

    21

  • PhpPowerpoint Documentation, Release 0.12.0

    22 Chapter 9. Frequently asked questions

  • CHAPTER 10

    Credits

    23

  • PhpPowerpoint Documentation, Release 0.12.0

    24 Chapter 10. Credits

  • CHAPTER 11

    References

    11.1 OpenXML

    Known as ISO/IEC 29500, Third edition, 2012-09-01

    ISO :

    Part 1: Fundamentals and Markup Language Reference

    Part 2: Open Packaging Conventions

    Part 3: Markup Compatibility and Extensibility

    Part 4: Transitional Migration Features

    MSDN :

    DocumentFormat.OpenXml.Presentation Namespace on MSDN

    Open XML SDK 2.5 with Validator

    11.2 OpenDocument

    Oasis OpenDocument Standard Version 1.2

    11.3 PowerPoint 97

    [MS-PPT]: PowerPoint (.ppt) Binary File Format

    OffVis : Microsoft Tool for reading PPT files

    25

  • PhpPowerpoint Documentation, Release 0.12.0

    26 Chapter 11. References

  • CHAPTER 12

    Indices and tables

    genindex

    modindex

    search

    27

    IntroductionFeaturesFile formatsContributing

    Installing/configuringRequirementsInstallationUsing samples

    General usageBasic exampleDocument information

    SlidesShapesRich textLineChartDrawingDrawing

    StylesFillBorderShadowAlignmentFontBulletColor

    Writers & readersOOXMLOpenDocumentHTMLPDF

    RecipesTitle

    Frequently asked questionsIs this the same with PHPPowerPoint that I found in CodePlex?Ive been running PHPPowerPoint from CodePlex flawlessly, but I cant use the latest PHPPowerPoint from GitHub. Why?

    CreditsReferencesOpenXMLOpenDocumentPowerPoint 97

    Indices and tables