Practical phppptx

Creating a new presentation

Introduction

Once the phppptx installation is completed, you can work with the library. To begin with, we are going to generate a presentation from scratch, that is, without an external template.

To do this, you'll create an example as simple as possible in which you'll add a text content and then, save the presentation with a name of your choice.

The version that supports the namespaces package is available for the Advanced and Premium licenses.

Due to phppptx internal performance, it is required to instance a new object for every file you generate. Otherwise, there may be unexpected results in the file content.

No-namespaces version

The full code for creating a PPTX is the following:

First, include the main class of phppptx CreatePptx:

This class loads automatically the rest of the available classes through an autoloader.

Then, create a new presentation:

You are going to create a new text, so use an array:

... and then add it to the slide with the method addText:

To, finally generate the PPTX:

With the file name output.pptx

Namespaces version, PHP 5.3 or higher

The full code for creating a presentation is as follows:

The differences between this and the no-namespaces version are limited to how you include the library and classes.

Include the main class, as it manages the loading of the rest of the classes:

Now you can create the new presentation:

If you're using a framework based on Composer such as Symfony, Laravel..., you need the namespaces package (available in Advanced and Premium licenses). You can also learn more about using phppptx with frameworks and CMS in the Cookbook.

Destination path/route

When generating the PPTX with the savePptx method, you can specify a relative or absolute path, to indicate the name and path where the file is going to be saved.

For example:

saves the PPTX in the script execution directory.

generates the PPTX in the sub-directory files, located one level above the current directory; or

saves it in the path /var/phppptx/files.

Before setting a path for saving your files, it is necessary to check that the execution user has the required read and write access rights.

Downloading the PPTX

phppptx includes the savePptxAndDownload method to generate and download the PPTX in just one step:

For example:

This download uses the following headers:

These headers work in most configurations, but in some cases might be insufficient. When this happens, it is necessary to create the PPTX with the savePptx method and use your own download headers.

Documentation

With each package of phppptx, full documentation comes in phppptx file format, which is the main reference to know in depth the software library. All public methods are detailed with a description of each of the available parameters.

In addition, it is advisable to visit:

Other useful resources

For further information and to solve doubts about the use of the library, there are several resources, both internal and external:

In addition, it is advisable to visit:

  • phppptx forum

    Forum of the great community of phppptx users, to solve doubts and queries

  • Contact

    Contact form, for direct communication with the phppptx team

  • Stack Overflow

    Reference forum for developers

Next - Adding contents