Cookbook

Download the generated PPTX

The savePptx phppptx method generates PPTX files in the file system, but does not download them on the spot, for example, when using a browser.

To generate and download the output files you can either choose the methods available in the library or work with some custom PHP code.

The savePptxAndDownload method

All phppptx licenses include the savePptxAndDownload method to create and download the PPTX. A simple example of use of this method would be as follows:

The download of the files happens thanks to a set of headers for PPTX files:

Alternative download code

The headers of the previous method are the standard ones for PPTX files, and so, are compatible with the majority of servers. However, in case of not functioning correctly, it is possible to work with any other method and headers to download the files. In this case, the first thing to do is generating the PPTX with the savePptx method, and then typing a custom code for the download.

An alternative method for the download would be the PHP ob_ functions, e.g.:

Delete files after the download

The savePptxAndDownload method creates and downloads a PPTX, but the default options don't delete it. If you want to do so after the download, you must set the second parameter as true.

E.g., to generate and download a PPTX, and delete it afterwards, write this PHP code:

Streams of files (Premium licenses only)

The package of the Premium licenses integrates the option of PPTX generation as a stream, that is, without saving the PPTX in the system files, and thus obtaining it directly in the browser or getting the output in the CLI mode.

You can set up dinamically this stream way in a script, or force it for all files in the configuration file config/phppptxconfig.ini.

The following example sets up the stream mode of phppptx:

The CLI mode with streams allows to redirect the output, e.g., to a file: