Practical phppptx

Adding contents

Introduction

In order to learn about content creation with phppptx, we are going to prepare a new PPTX with some different contents included.

New PPTX

As a first step, create the PPTX, instantiating the class CreatePptx:

Now, add the new contents for this $pptx object. Contents are added to the internal active slide.

Slides

The default PPTX includes one slide. To add a new slide, call addSlide:

For this presentation sample, insert a new slide:

The same layout of the last slide is applied to the new slide. This can be changed using the 'layout' option:

A custom layout can be applied to the first slide when creating the new presentation:

When creating a presentation from scratch, the available layouts are the same as the ones in MS PowerPoint:

  • Title Slide
  • Title and Content
  • Section Header
  • Two Content
  • Comparison
  • Title Only
  • Blank
  • Content with Caption
  • Picture with Caption
  • Title and Vertical Text
  • Vertical Title and Text

When using templates, new layouts may be added to the presentation.

Slides can be organized into groups (sections) using addSection:

Text contents

After at least one slide exists in the presentation, new contents can be inserted. The addText method creates a text as follows:

This method includes the following parameters:

  • $contents: array with contents and styles.
  • $position: position to place the new content. This can be an existing placeholder in the layout or a new text box.
  • $paragraphStyles: array with paragraph styles to be applied.
  • $options: extra options.

Add to the active slide two text contents:

It is possible to apply multiple styles to the added text:

When inserting a text in a slide, the $position parameter admits one of the following two options:

  • 'placeholder': the content is added in a placeholder of the layout or in an existing text box by its name, descr, position or type. The getActiveSlideInformation method or Indexer can be used to return the existing placeholders in the layouts.
  • 'new': a new text box is generated to add the content. Coordinate and size values must be set.

If the target text box has already some content, it is possible to insert the new content after the previous one:

On the other hand, you can replace the old content with the new one:

Active slide

New contents are always added to the internal active slide. By default, the internal active slide is the first slide.

The setActiveSlide methods allow to modify the internal active slide by choosing an existing slide position in the presentation:

It is also possible to create a new slide and turn it active with the very same method:

The getActiveSlide method returns the current internal active slide value.

Text boxes

New empty text boxes can be added with the help of addTextBox:

This method includes the following parameters:

  • $position: set the coordinate and size values
  • $textBoxStyles: text box styles
  • $options: extra options

Let's add a new text box with a custom descr (altText) value and add a text into it:

Lists

To create lists, use addList:

A sample to add a new list is the following:

Links

To add a link, use the addText method with the hyperlink option:

Tips and tricks

The value of the internal active slide can be returned using the getActiveSlide method.

setActiveSlide allows using -1 as position to choose the last slide.

Using addTextBox, if a text box doesn't have any style applied or a content, the text box is added to the slide but not visually displayed.

Coordinates, sizes and other options included in phppptx are shown in EMUs. Measure units such as PT or PX can be easily converted to EMUs. For more information on this matter, check the page EMUs measuring unit.

Next - Working with templates