Save Presentations in .NET

Overview

Open Presentations in C# described how to use the Presentation class to open a presentation. This article explains how to create and save presentations. The Presentation class contains a presentation’s contents. Whether you’re creating a presentation from scratch or modifying an existing one, you’ll want to save it when you’re finished. With Aspose.Slides for .NET, you can save to a file or stream. This article explains the different ways to save a presentation.

Save Presentations to Files

Save a presentation to a file by calling the Presentation class’s Save method. Pass the file name and save format to the method. The following example show how to save a presentation with Aspose.Slides.

// Instantiate the Presentation class that represents a presentation file.
using (Presentation presentation = new Presentation())
{
    // Do some work here...

    // Save the presentation to a file.
    presentation.Save("Output.pptx", SaveFormat.Pptx);
}

Save Presentations to Streams

You can save a presentation to a stream by passing an output stream to the Presentation class’s Save method. A presentation can be written to many stream types. In the example below, we create a new presentation and save it to a file stream.

// Instantiate the Presentation class that represents a presentation file.
using (Presentation presentation = new Presentation())
{
    using (FileStream fileStream = new FileStream("Output.pptx", FileMode.Create))
    {
        // Save the presentation to the stream.
        presentation.Save(fileStream, SaveFormat.Pptx);
    }
}

Save Presentations with a Predefined View Type

Aspose.Slides lets you set the initial view that PowerPoint uses when the generated presentation opens through the ViewProperties class. Set the LastView property to a value from the ViewType enumeration.

using (Presentation presentation = new Presentation())
{
    presentation.ViewProperties.LastView = ViewType.SlideMasterView;
    presentation.Save("SlideMasterView.pptx", SaveFormat.Pptx);
}

Save Presentations in the Strict Office Open XML Format

Aspose.Slides lets you save a presentation in the Strict Office Open XML format. Use the PptxOptions class and set its conformance property when saving. If you set Conformance.Iso29500_2008_Strict, the output file is saved in the Strict Office Open XML format.

The example below creates a presentation and saves it in the Strict Office Open XML format.

PptxOptions options = new PptxOptions()
{
    Conformance = Conformance.Iso29500_2008_Strict
};

// Instantiate the Presentation class that represents a presentation file.
using (Presentation presentation = new Presentation())
{
    // Save the presentation in the Strict Office Open XML format.
    presentation.Save("StrictOfficeOpenXml.pptx", SaveFormat.Pptx, options);
}

Save Presentations in Office Open XML Format in Zip64 Mode

An Office Open XML file is a ZIP archive that imposes 4 GB (2^32 bytes) limits on the uncompressed size of any file, the compressed size of any file, and the total size of the archive, and it also limits the archive to 65,535 (2^16-1) files. ZIP64 format extensions raise these limits to 2^64.

The IPptxOptions.Zip64Mode property lets you choose when to use ZIP64 format extensions when saving an Office Open XML file.

This property provides the following modes:

  • IfNecessary uses ZIP64 format extensions only if the presentation exceeds the limitations above. This is the default mode.
  • Never never uses ZIP64 format extensions.
  • Always always uses ZIP64 format extensions.

The following code demonstrates how to save a presentation as a PPTX file with ZIP64 format extensions enabled:

using (Presentation presentation = new Presentation("Sample.pptx"))
{
    presentation.Save("OutputZip64.pptx", SaveFormat.Pptx, new PptxOptions()
    {
        Zip64Mode = Zip64Mode.Always
    });
}

Save Presentations in Office Open XML Format with Compression Levels

When working with large presentations, you can adjust the compression level to balance file size and processing time. Depending on your requirements, you may prefer faster processing or smaller output files.

Aspose.Slides provides the IPptxOptions.CompressionLevel property, which allows you to specify the compression level used when saving a presentation in Office Open XML format.

The following compression levels are available:

  • None: No compression is applied. Files are stored as-is.
  • Level1: The fastest compression with the lowest compression ratio.
  • Level2: Faster compression with a slightly better compression ratio than Level1.
  • Level3: Provides better compression than Level2 with a moderate impact on processing time.
  • Level4: Provides better compression than Level3.
  • Level5: Provides improved compression over Level4 with additional processing time.
  • Level6: Standard compression that offers a good balance between processing speed and file size. This is the default compression level.
  • Level7: Provides better compression than Level6 with slower processing.
  • Level8: Provides better compression than Level7.
  • Level9: Maximum compression. Produces the smallest file size at the cost of the longest processing time.

The following example demonstrates how to save a presentation as a PPTX file without compression:

using (Presentation pres = new Presentation("Sample.pptx"))
{
    pres.Save("Sample-out.pptx", SaveFormat.Pptx, new PptxOptions
    {
        CompressionLevel = CompressionLevel.None
    });
}

This example shows how to save a presentation as a PPTX file with maximum compression:

using (Presentation pres = new Presentation("Sample.pptx"))
{
    pres.Save("Sample-level9.pptx", SaveFormat.Pptx, new PptxOptions
    {
        CompressionLevel = CompressionLevel.Level9
    });
}

Save Presentations without Refreshing the Thumbnail

The PptxOptions.RefreshThumbnail property controls thumbnail generation when saving a presentation to PPTX:

  • If set to true, the thumbnail is refreshed during save. This is the default.
  • If set to false, the current thumbnail is preserved. If the presentation has no thumbnail, none is generated.

In the code below, the presentation is saved to PPTX without refreshing its thumbnail.

using (Presentation presentation = new Presentation("Sample.pptx"))
{
    presentation.Save("Output.pptx", SaveFormat.Pptx, new PptxOptions()
    {
        RefreshThumbnail = false
    });
}

Save Progress Updates in Percentage

The IProgressCallback interface is used via the ProgressCallback property exposed by the ISaveOptions interface and the abstract SaveOptions class. Assign an IProgressCallback implementation to ProgressCallback to receive save-progress updates as a percentage.

The following code snippets show how to use IProgressCallback.

ISaveOptions saveOptions = new PdfOptions();
saveOptions.ProgressCallback = new ExportProgressHandler();

using (Presentation presentation = new Presentation("Sample.pptx"))
{
    presentation.Save("Output.pdf", SaveFormat.Pdf, saveOptions);
}
class ExportProgressHandler : IProgressCallback
{
    public void Reporting(double progressValue)
    {
        // Use the progress percentage value here.
        int progress = Convert.ToInt32(progressValue);

        Console.WriteLine(progress + "% of the file has been converted.");
    }
}

FAQ

Is “fast save” (incremental save) supported so only changes are written?

No. Saving creates the full target file each time; incremental “fast save” isn’t supported.

Is it thread-safe to save the same Presentation instance from multiple threads?

No. A Presentation instance isn’t thread-safe; save it from a single thread.

What happens to hyperlinks and externally linked files when saving?

Hyperlinks are preserved. External linked files (e.g., videos via relative paths) aren’t copied automatically—ensure the referenced paths remain accessible.

Can I set/save document metadata (Author, Title, Company, Date)?

Yes. Standard document properties are supported and will be written to the file on save.