Create Presentations in PHP

Overview

This article shows how to create a presentation in Aspose.Slides, add a text box to its first slide, and save the result as a file. It also shows how to create and save an empty presentation, and how to open an existing presentation in a supported format and save it in another format. A short FAQ at the end covers common questions about formats, templates, slide sizing, units, memory usage, threading, licensing, digital signatures, and VBA support.

Before you begin, install Aspose.Slides for PHP via Java with Composer and start PHP/Java Bridge in Apache Tomcat. See Installation for the complete setup. The examples below expect Tomcat to be running on localhost:8080 and the Composer vendor folder to be next to the script.

Create a PowerPoint Presentation

To create a presentation and put a text box on its first slide, follow these steps:

  1. Create an instance of the Presentation class. A new presentation already contains one empty slide.
  2. Get that slide from the collection returned by Presentation::getSlides, by its index, 0.
  3. Add a rectangle with the ShapeCollection::addAutoShape method and set its text with TextFrame::setText.
  4. Save the presentation as a PPTX file with the Presentation::save method.
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
require_once(__DIR__ . "/vendor/aspose/slides/lib/aspose.slides.php");

use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 50, 50, 400, 100);
    $shape->getTextFrame()->setText("Hello, Aspose.Slides!");
    $presentation->save(__DIR__ . "/hello.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

The two require_once lines load the PHP/Java Bridge client from Tomcat and the Aspose.Slides classes from the Composer package. The rectangle’s top-left corner is 50 points from the left edge and 50 points from the top edge of the slide, and the rectangle is 400 points wide and 100 points high. The saved file contains one slide with that rectangle and its text. Without a license, Aspose.Slides also adds an evaluation watermark to every slide it saves; see Licensing.

Create and Save a Presentation

To create an empty presentation and save it, create an instance of the Presentation class and save it in any format of the SaveFormat enumeration. The result is a presentation with one empty slide.

<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
require_once(__DIR__ . "/vendor/aspose/slides/lib/aspose.slides.php");

use aspose\slides\Presentation;
use aspose\slides\SaveFormat;

$presentation = new Presentation();
try {
    $presentation->save(__DIR__ . "/OutputPresentation.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

Open and Save a Presentation

To convert a presentation from one format to another, open it by passing its path to the Presentation constructor, then save it in the target format. Aspose.Slides detects the input format, such as PPT, PPTX, or ODP, from the file itself.

The example below expects an OpenDocument presentation named Sample.odp next to the script and saves it as PPTX.

<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
require_once(__DIR__ . "/vendor/aspose/slides/lib/aspose.slides.php");

use aspose\slides\Presentation;
use aspose\slides\SaveFormat;

$presentation = new Presentation(__DIR__ . "/Sample.odp");
try {
    $presentation->save(__DIR__ . "/OutputPresentation.pptx", SaveFormat::Pptx);
} finally {
    $presentation->dispose();
}

FAQ

What formats can I save a new presentation to?

You can save to PPTX, PPT, and ODP, and export to PDF, XPS, HTML, SVG, and images, among others.

Can I start from a template (POTX/POTM) and save as a regular PPTX?

Yes. Load the template and save to the desired format; POTX/POTM/PPTM and similar formats are supported.

How do I control slide size/aspect ratio when creating a presentation?

Set the slide size (including presets like 4:3 and 16:9 or custom dimensions) and choose how content should scale.

In what units are sizes and coordinates measured?

In points: 1 inch equals 72 units.

How do I handle very large presentations (with many media files) to reduce memory usage?

Use BLOB management strategies, limit in-memory storage by leveraging temporary files, and prefer file-based workflows over purely in-memory streams.

Can I create/save presentations in parallel?

You cannot operate on the same Presentation instance from multiple threads. Run separate, isolated instances per thread or process.

How do I remove the trial watermark and limitations?

Apply a license once per process. The license XML must remain unmodified, and the license setup should be synchronized if multiple threads are involved.

Can I digitally sign the PPTX I create?

Yes. Digital signatures (adding and verifying) are supported for presentations.

Are macros (VBA) supported in created presentations?

Yes. You can create/edit VBA projects and save macro-enabled files such as PPTM/PPSM.