Save Presentation
Overview
The Presentation class holds a presentation’s content. Whether creating a presentation from scratch or modifying an existing one, when finished, you want to save the presentation. With Aspose.Slides for Node.js via Java, it can be saved as a file or stream. This article explains how to save a presentation in different ways:
Save Presentation to File
Save a presentation to file by calling the Presentation class Save method. Simply pass the file name and SaveFormat to the Save method.
The examples that follow show how to save a presentation with Aspose.Slides for Node.js via Java.
// Instantiate a Presentation object that represents a PPT file
var pres = new aspose.slides.Presentation();
try {
// ...do some work here...
// Save your presentation to a file
pres.save("demoPass.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Save Presentation to Stream
It is possible to save a presentation to a stream by passing an output stream to the Presentation class Save method. There are many types of streams to which a presentation can be saved. In the below example we have created a new Presentation file, add text in shape and Save the presentation to the stream.
// Instantiate a Presentation object that represents a PPT file
var pres = new aspose.slides.Presentation();
try {
var shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 200, 200);
// Add text to shape
shape.getTextFrame().setText("This demo shows how to Create PowerPoint file and save it to Stream.");
var os = java.newInstanceSync("java.io.FileOutputStream", "Save_As_Stream_out.pptx");
pres.save(os, aspose.slides.SaveFormat.Pptx);
os.close();
} catch (e) {console.log(e);
} finally {
if (pres != null) {
pres.dispose();
}
}
Save Presentation with Predefined View Type
Aspose.Slides for Node.js via Java provides a facility to set the view type for the generated presentation when it is opened in PowerPoint through the ViewProperties class. The setLastView property is used to set the view type by using the ViewType enumerator.
// Opening the presentation file
var pres = new aspose.slides.Presentation();
try {
// Setting view type
pres.getViewProperties().setLastView(aspose.slides.ViewType.SlideMasterView);
// Saving presentation
pres.save("newDemo.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Saving Presentations to Strict Office Open XML Format
Aspose.Slides allows you to save the presentation in Strict Office Open XML format. For that purpose, it provides the PptxOptions class where you can set the Conformance property while saving the presentation file. If you set its value as Conformance.Iso29500_2008_Strict, then the output presentation file will be saved in Strict Open XML format.
The following sample code creates a presentation and saves it in the Strict Office Open XML format. While calling the Save method for the presentation, the PptxOptions object is passed into it with the Conformance property set as Conformance.Iso29500_2008_Strict.
// Instantiate a Presentation object that represents a PPT file
var pres = new aspose.slides.Presentation();
try {
// Get the first slide
var slide = pres.getSlides().get_Item(0);
// Add an autoshape of type line
slide.getShapes().addAutoShape(aspose.slides.ShapeType.Line, 50, 150, 300, 0);
// Set Strict Office Open XML Format save options
var options = new aspose.slides.PptxOptions();
options.setConformance(aspose.slides.Conformance.Iso29500_2008_Strict);
// Save your presentation to a file
pres.save("demoPass.pptx", aspose.slides.SaveFormat.Pptx, options);
} finally {
if (pres != null) {
pres.dispose();
}
}
Saving Presentations to Office Open XML format in Zip64 mode
An Office Open XML file is a ZIP-archive that has a 4 GB (2^32 bytes) limit on uncompressed size of a file, compressed size of a file, and total size of the archive, as well as a limit of 65,535 (2^16-1) files in the archive. ZIP64 format extensions increase the limits to 2^64.
The new PptxOptions.Zip64Mode property allows you to choose when to use ZIP64 format extensions for the saved Office Open XML file.
This property provides the following modes:
- Zip64Mode.IfNecessary means that ZIP64 format extensions will only be used if the presentation falls outside the above limitations. This is the default mode.
- Zip64Mode.Never means that ZIP64 format extensions will not be used.
- Zip64Mode.Always means that ZIP64 format extensions will always be used.
The following code demonstrates how to save the presentation to PPTX format with ZIP64 format extensions:
var pres = new aspose.slides.Presentation("Sample.pptx");
try {
var pptxOptions = new aspose.slides.PptxOptions();
pptxOptions.setZip64Mode(aspose.slides.Zip64Mode.Always);
pres.save("Sample-zip64.pptx", aspose.slides.SaveFormat.Pptx, pptxOptions);
} finally {
if (pres != null) {
pres.dispose();
}
}
NOTE
Saving in the Zip64Mode.Never mode will throw a PptxException if the presentation cannot be saved in ZIP32 format.Save Progress Updates in Percentage
New ProgressCallback class has been added to SaveOptions class and SaveOptions abstract class. ProgressCallback class represents a callback object for saving progress updates in percentage.
The following code snippets below show how to use ProgressCallback class:
var pres = new aspose.slides.Presentation("ConvertToPDF.pptx");
try {
let saveOptions = new aspose.slides.PdfOptions();
const ExportProgressHandler = java.newProxy("com.aspose.slides.IProgressCallback", {
reporting: function(progressValue) {
const progress = Math.floor(progressValue);
console.log(`${progress}% file converted`);
}
});
saveOptions.setProgressCallback(ExportProgressHandler);
pres.save("ConvertToPDF.pdf", aspose.slides.SaveFormat.Pdf, saveOptions);
} finally {
pres.dispose();
}