How to Get Started with Aspose.Slides FOSS for Java

How to Get Started with Aspose.Slides FOSS for Java

aspose-slides-foss for Java is a free, MIT-licensed library for creating and editing PowerPoint .pptx files — no Microsoft Office required, available on Maven Central.

Step-by-Step Guide

Step 1: Add the Maven Dependency

Add the dependency to your pom.xml (Java 21 or later required):

<dependency>
    <groupId>org.aspose.slides.foss</groupId>
    <artifactId>aspose-slides-foss</artifactId>
    <version>1.0.0</version>
</dependency>

Verify the package resolves correctly by building the project:

mvn dependency:resolve

Step 2: Import Required Classes

Import the classes you need for loading presentations and saving:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.ITextFrame;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;

Step 3: Create a Presentation

Construct a Presentation with no arguments to start with one blank slide. Always use try-with-resources to ensure internal resources are released:

import org.aspose.slides.foss.Presentation;

try (Presentation prs = new Presentation()) {
    System.out.println("Slides: " + prs.getSlides().size());
    prs.save("new_presentation.pptx");
}

Step 4: Add a Shape with Text

Use slide.getShapes().addAutoShape() to insert a rectangle, then call addTextFrame() to add text content:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.ITextFrame;
import org.aspose.slides.foss.IPortionFormat;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.NullableBool;

try (Presentation prs = new Presentation()) {
    ISlide slide = prs.getSlides().get(0);
    IAutoShape shape = slide.getShapes().addAutoShape(
        ShapeType.RECTANGLE, 50, 50, 400, 150
    );
    ITextFrame tf = shape.addTextFrame("Hello from Aspose.Slides FOSS!");
    IPortionFormat fmt = tf.getParagraphs().get(0).getPortions().get(0).getPortionFormat();
    fmt.setFontHeight(24);
    fmt.setFontBold(NullableBool.TRUE);
    prs.save("with_shape.pptx");
}

Step 5: Apply a Fill and Save

Set a solid fill color on the shape before saving:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.IAutoShape;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.FillType;
import org.aspose.slides.foss.drawing.Color;

try (Presentation prs = new Presentation()) {
    IAutoShape shape = prs.getSlides().get(0).getShapes().addAutoShape(
        ShapeType.RECTANGLE, 100, 100, 400, 200
    );
    shape.getFillFormat().setFillType(FillType.SOLID);
    shape.getFillFormat().getSolidFillColor().setColor(new Color(70, 130, 180));
    shape.addTextFrame("Styled shape");
    prs.save("styled.pptx");
}

Common Issues and Fixes

ClassNotFoundException for org.aspose.slides.foss.Presentation The Maven dependency is not resolved. Run mvn dependency:resolve and check that the artifact is available in Maven Central. Verify the version in pom.xml.

UnsupportedOperationException when calling certain methods Some features (charts, animations, PDF export) throw UnsupportedOperationException in this release. Check the known limitations section of the API reference before using advanced features.

Shape coordinates seem off Coordinates and dimensions are in EMU (English Metric Units). One point is approximately 12700 EMU. The default slide is 9144000 × 6858000 EMU.

File not found when loading an existing PPTX Pass an absolute path or ensure the working directory is set correctly:

import java.nio.file.Paths;
String path = Paths.get("presentations", "existing.pptx").toAbsolutePath().toString();
try (Presentation prs = new Presentation(path)) { ... }

Frequently Asked Questions

Does aspose-slides-foss require Microsoft Office?

No. The library creates and reads .pptx files natively in pure Java with no dependency on Microsoft Office, COM automation, or Windows APIs.

Which Java versions are supported?

Java 21 or later. The library runs on Windows, macOS, Linux, and Docker containers.

Is the library free for commercial use?

Yes. It is released under the MIT License. You may use, modify, and redistribute it for any purpose, including commercial applications.

Can I load an existing PPTX file?

Yes. Pass the file path to the Presentation constructor:

try (Presentation prs = new Presentation("existing.pptx")) {
    System.out.println("Loaded " + prs.getSlides().size() + " slides");
    prs.save("copy.pptx");
}

Do I need to close the Presentation explicitly?

Yes. Presentation implements AutoCloseable. Always use try-with-resources (try (Presentation prs = new Presentation()) { ... }) to guarantee cleanup.

See Also

 English