Presentation — Aspose.Slides FOSS for Java API Reference
The Presentation class is the root object for creating, loading, and saving PowerPoint .pptx files in Aspose.Slides FOSS for Java. It implements IPresentation.
Package: org.aspose.slides.foss
import org.aspose.slides.foss.*;public class Presentation implements IPresentationInheritance
IPresentation -> Presentation
Constructors
| Signature | Description |
|---|---|
Presentation() | Create a new blank presentation with one slide. |
Presentation(String path) | Open a presentation from the given file path. |
Presentation(InputStream in) | Open a presentation from the given input stream. |
Examples:
import org.aspose.slides.foss.*;
// Create a new empty presentation
Presentation prs = new Presentation();
// Open an existing PPTX file
Presentation prs2 = new Presentation("deck.pptx");
// Load from a stream
InputStream stream = new FileInputStream("deck.pptx");
Presentation prs3 = new Presentation(stream);Properties
| Property | Type | Access | Description |
|---|---|---|---|
getSlides() | ISlideCollection | Read | Ordered collection of slides in the presentation. |
getMasters() | IMasterSlideCollection | Read | Collection of master slides. |
getLayoutSlides() | IGlobalLayoutSlideCollection | Read | Collection of all layout slides across all masters. |
getCommentAuthors() | ICommentAuthorCollection | Read | Collection of comment authors. |
getDocumentProperties() | IDocumentProperties | Read | Core, application, and custom document metadata. |
getImages() | IImageCollection | Read | Collection of all images embedded in the presentation. |
getNotesSize() | INotesSize | Read | Notes slide size settings. |
getSourceFormat() | SourceFormat | Read | Format of the loaded presentation source. |
getCurrentDateTime() / setCurrentDateTime(LocalDateTime) | LocalDateTime | Read/Write | Date and time used for date-time placeholders. |
getFirstSlideNumber() / setFirstSlideNumber(int) | int | Read/Write | First slide number in the presentation. |
Methods
save(String path)
Save the presentation to a file (default PPTX format).
| Parameter | Type | Description |
|---|---|---|
path | String | Destination file path. |
prs.save("output.pptx");save(OutputStream stream)
Save the presentation to an output stream.
| Parameter | Type | Description |
|---|---|---|
stream | OutputStream | Destination stream. |
save(String path, SaveFormat format)
Save the presentation to a file in the specified format.
| Parameter | Type | Description |
|---|---|---|
path | String | Destination file path. |
format | SaveFormat | Output format (e.g., SaveFormat.PPTX). |
prs.save("output.pptx", SaveFormat.PPTX);save(OutputStream stream, SaveFormat format)
Save the presentation to a stream in the specified format.
save(String path, SaveFormat format, ISaveOptions options)
Save the presentation to a file with additional options.
| Parameter | Type | Description |
|---|---|---|
path | String | Destination file path. |
format | SaveFormat | Output format. |
options | ISaveOptions | Save options controlling output behavior. |
Usage Examples
Create a Presentation with a Shape
import org.aspose.slides.foss.*;
Presentation prs = new Presentation();
ISlide slide = prs.getSlides().get(0);
IAutoShape shape = slide.getShapes().addAutoShape(
ShapeType.RECTANGLE, 50, 50, 300, 100);
shape.addTextFrame("Hello, Slides!");
prs.save("hello.pptx", SaveFormat.PPTX);Open, Inspect, and Re-Save
import org.aspose.slides.foss.*;
Presentation prs = new Presentation("existing.pptx");
System.out.println("Slides: " + prs.getSlides().size());
for (int i = 0; i < prs.getSlides().size(); i++) {
ISlide slide = prs.getSlides().get(i);
System.out.println(" Slide " + i + ": " + slide.getShapes().size() + " shapes");
}
prs.save("existing-updated.pptx", SaveFormat.PPTX);Set Document Properties
import org.aspose.slides.foss.*;
Presentation prs = new Presentation();
prs.getDocumentProperties().setTitle("Q1 Results");
prs.getDocumentProperties().setAuthor("Finance Team");
prs.getDocumentProperties().setSubject("Quarterly Review");
prs.save("q1.pptx", SaveFormat.PPTX);