Save

Save(string, SaveFormat)

Saves all slides of a presentation to a file with the specified format.

public void Save(string fname, SaveFormat format)
ParameterTypeDescription
fnameStringPath to the created file.
formatSaveFormatFormat of the exported data.

See Also


Save(Stream, SaveFormat)

Saves all slides of a presentation to a stream in the specified format.

public void Save(Stream stream, SaveFormat format)
ParameterTypeDescription
streamStreamOutput stream.
formatSaveFormatFormat of the exported data.

See Also


Save(string, SaveFormat, ISaveOptions)

Saves all slides of a presentation to a file with the specified format and with additional options.

public void Save(string fname, SaveFormat format, ISaveOptions options)
ParameterTypeDescription
fnameStringPath to the created file.
formatSaveFormatFormat of the exported data.
optionsISaveOptionsAdditional format options.

Examples

The following example shows how to convert PowerPoint to HTML using C#.

// Instantiates a presentation object that represents a presentation file e.g. PPT, PPTX, ODP etc.
using (Presentation presentation = new Presentation("Convert_HTML.pptx"))
{
    HtmlOptions htmlOpt = new HtmlOptions();
    NotesCommentsLayoutingOptions options = new NotesCommentsLayoutingOptions()
    options.NotesPosition = NotesPositions.BottomFull;
    htmlOpt.SlidesLayoutOptions = options;
    htmlOpt.HtmlFormatter = HtmlFormatter.CreateDocumentFormatter("", false);
    // Saves the presentation to HTML
    presentation.Save("ConvertWholePresentationToHTML_out.html", SaveFormat.Html, htmlOpt);
}

The following example shows how to convert PowerPoint to responsive HTML using C#.

// Instantiates a Presentation object that represents a presentation file
using (Presentation presentation = new Presentation("Convert_HTML.pptx"))
{
    ResponsiveHtmlController controller = new ResponsiveHtmlController();
    HtmlOptions htmlOptions = new HtmlOptions { HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller) };
    // Saves the presentation to HTML
    presentation.Save("ConvertPresentationToResponsiveHTML_out.html", SaveFormat.Html, htmlOptions);
}

The following example shows how to convert PowerPoint to HTML with notes using C#.

using (Presentation pres = new Presentation("Presentation.pptx"))
{
    HtmlOptions opt = new HtmlOptions();
    NotesCommentsLayoutingOptions options = new NotesCommentsLayoutingOptions()
    options.NotesPosition = NotesPositions.BottomFull;
    htmlOpt.SlidesLayoutOptions = options;
    // Saves notes pages
    pres.Save("Output.html", SaveFormat.Html, opt);
}

The following example shows how to convert PowerPoint to HTML with original fonts using C#.

using (Presentation pres = new Presentation("input.pptx"))
{
    // Excludes default presentation fonts
    string[] fontNameExcludeList = { "Calibri", "Arial" };
    EmbedAllFontsHtmlController embedFontsController = new EmbedAllFontsHtmlController(fontNameExcludeList);
    HtmlOptions htmlOptionsEmbed = new HtmlOptions
    {
        HtmlFormatter = HtmlFormatter.CreateCustomFormatter(embedFontsController)
    };
    pres.Save("input-PFDinDisplayPro-Regular-installed.html", SaveFormat.Html, htmlOptionsEmbed);
}

The following example shows how to convert PowerPoint to HTML with high-quality images at 150 DPI using C#.

using (Presentation pres = new Presentation("InputDoc.pptx"))
{
	HtmlOptions htmlOpts = new HtmlOptions
	{
		PicturesCompression = PicturesCompression.Dpi150
	};
	pres.Save("OutputDoc-dpi150.html", Aspose.Slides.Export.SaveFormat.Html, htmlOpts);
}

The following example shows how to convert PowerPoint to HTML with full quality images using C#.

using (Presentation pres = new Presentation("InputDoc.pptx"))
{
	HtmlOptions htmlOpts = new HtmlOptions
	{
		DeletePicturesCroppedAreas = false
	};
	pres.Save("Outputdoc-noCrop.html", Aspose.Slides.Export.SaveFormat.Html, htmlOpts);
}

The following example shows how to convert Slide to HTML using C#.

public static void Run()
{
    using (Presentation presentation = new Presentation("Individual-Slide.pptx"))
    {
        HtmlOptions htmlOptions = new HtmlOptions();
    NotesCommentsLayoutingOptions options = new NotesCommentsLayoutingOptions()
    options.NotesPosition = NotesPositions.BottomFull;
    htmlOpt.SlidesLayoutOptions = options;
        htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(new CustomFormattingController());
        // Saves File
        for (int i = 0; i < presentation.Slides.Count; i++)
            presentation.Save("Individual Slide" + (i + 1) + "_out.html", new[] { i + 1 }, SaveFormat.Html, htmlOptions);
    }
}
public class CustomFormattingController : IHtmlFormattingController
{
    void IHtmlFormattingController.WriteDocumentStart(IHtmlGenerator generator, IPresentation presentation)
    {}
    void IHtmlFormattingController.WriteDocumentEnd(IHtmlGenerator generator, IPresentation presentation)
    {}
    void IHtmlFormattingController.WriteSlideStart(IHtmlGenerator generator, ISlide slide)
    {
        generator.AddHtml(string.Format(SlideHeader, generator.SlideIndex + 1));
    }
    void IHtmlFormattingController.WriteSlideEnd(IHtmlGenerator generator, ISlide slide)
    {
        generator.AddHtml(SlideFooter);
    }
    void IHtmlFormattingController.WriteShapeStart(IHtmlGenerator generator, IShape shape)
    {}
    void IHtmlFormattingController.WriteShapeEnd(IHtmlGenerator generator, IShape shape)
    {}
    private const string SlideHeader = "<div class=\"slide\" name=\"slide\" id=\"slide{0}\">";
    private const string SlideFooter = "</div>";
}

The following example shows how to save CSS and Images when exporting To HTML using C#.

using (Presentation pres = new Presentation("pres.pptx"))
{
	CustomHeaderAndFontsController htmlController = new CustomHeaderAndFontsController("styles.css");
	HtmlOptions options = new HtmlOptions
	{
		HtmlFormatter = HtmlFormatter.CreateCustomFormatter(htmlController),
	};
	pres.Save("pres.html", SaveFormat.Html, options);
}
public class CustomHeaderAndFontsController : EmbedAllFontsHtmlController
{
    // Custom header template
    const string Header = "<!DOCTYPE html>\n" +
                            "<html>\n" +
                            "<head>\n" +
                            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" +
                            "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\">\n" +
                            "<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\">\n" +
                            "</head>";
    private readonly string m_cssFileName;
    public CustomHeaderAndFontsController(string cssFileName)
    {
        m_cssFileName = cssFileName;
    }
    public override void WriteDocumentStart(IHtmlGenerator generator, IPresentation presentation)
    {
        generator.AddHtml(string.Format(Header, m_cssFileName));
        WriteAllFonts(generator, presentation);
    }
    public override void WriteAllFonts(IHtmlGenerator generator, IPresentation presentation)
    {
        generator.AddHtml("<!-- Embedded fonts -->");
        base.WriteAllFonts(generator, presentation);
    }
}

The following example shows how to link all fonts when converting Presentation to HTML using C#.

using (Presentation pres = new Presentation("pres.pptx"))
{
    //Excludes default presentation fonts
    string[] fontNameExcludeList = { "Calibri", "Arial" };
    Paragraph para = new Paragraph();
    ITextFrame txt;
    LinkAllFontsHtmlController linkcont = new LinkAllFontsHtmlController(fontNameExcludeList, @"C:\Windows\Fonts\");;
    HtmlOptions htmlOptionsEmbed = new HtmlOptions
    {
        HtmlFormatter = HtmlFormatter.CreateCustomFormatter(linkcont)
    };
    pres.Save("pres.html", SaveFormat.Html, htmlOptionsEmbed);
}

The following example shows how to LinkAllFontsHtmlController is implemented using C#.

public class LinkAllFontsHtmlController : EmbedAllFontsHtmlController
{
    private readonly string m_basePath;
    public LinkAllFontsHtmlController(string[] fontNameExcludeList, string basePath) : base(fontNameExcludeList)
    {
        m_basePath = basePath;
    }
    public override void WriteFont
    (
            IHtmlGenerator generator,
            IFontData originalFont,
            IFontData substitutedFont,
            string fontStyle,
            string fontWeight,
            byte[] fontData)
    {
        try
        {
            string fontName = substitutedFont == null ? originalFont.FontName : substitutedFont.FontName;
            string path = fontName + ".woff"; //Some path sanitaze may be needed
            File.WriteAllBytes(Path.Combine(m_basePath, path), fontData);
            generator.AddHtml("<style>");
            generator.AddHtml("@font-face { ");
            generator.AddHtml("font-family: '" + fontName + "'; ");
            generator.AddHtml("src: url('" + path + "')");
            generator.AddHtml(" }");
            generator.AddHtml("</style>");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

The following example shows how to convert PowerPoint to responsive HTML using C#.

using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	HtmlOptions saveOptions = new HtmlOptions();
	saveOptions.SvgResponsiveLayout = true;
	presentation.Save("SomePresentation-out.html", SaveFormat.Html, saveOptions);
}

The following example shows how to export Media files to HTML using C#.

// Loads a presentation
using (Presentation pres = new Presentation())
{
    string path = "C:/out/";
    const string fileName = "ExportMediaFiles_out.html";
    const string baseUri = "http://www.example.com/";
    using (FileStream fileStream = new FileStream("my_video.avi", FileMode.Open, FileAccess.Read))
    {
        IVideo video = pres.Videos.AddVideo(fileStream, LoadingStreamBehavior.ReadStreamAndRelease);
        ISlide slide = pres.Slides[0];
        slide.Shapes.AddVideoFrame(10, 10, 100, 100, video);
    }
    VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path, fileName, baseUri);
    // Sets HTML options
    HtmlOptions htmlOptions = new HtmlOptions(controller);
    SVGOptions svgOptions = new SVGOptions(controller);
    htmlOptions.HtmlFormatter = HtmlFormatter.CreateCustomFormatter(controller);
    htmlOptions.SlideImageFormat = SlideImageFormat.Svg(svgOptions);
    // Saves the file
    pres.Save(Path.Combine(path, fileName), SaveFormat.Html, htmlOptions);
}

See Also


Save(Stream, SaveFormat, ISaveOptions)

Saves all slides of a presentation to a stream in the specified format and with additional options.

public void Save(Stream stream, SaveFormat format, ISaveOptions options)
ParameterTypeDescription
streamStreamOutput stream.
formatSaveFormatFormat of the exported data.
optionsISaveOptionsAdditional format options.

Exceptions

exceptioncondition
NotSupportedExceptionIf you try to save encrypted file in none Office 2007-2010 format

See Also


Save(IXamlOptions)

Saves all slides of a presentation to a set of files representing XAML markup.

public void Save(IXamlOptions options)
ParameterTypeDescription
optionsIXamlOptionsThe XAML format options.

Examples

[C#]
using (Presentation pres = new Presentation("pres.pptx"))
{
	pres.Save(new XamlOptions { ExportHiddenSlides = true });
}

See Also


Save(string, int[], SaveFormat)

Saves specified slides of a presentation to a file with the specified format with page number keeping.

public void Save(string fname, int[] slides, SaveFormat format)
ParameterTypeDescription
fnameStringPath to the created file.
slidesInt32[]Array with slide positions, starting from 1.
formatSaveFormatFormat of the exported data.

Exceptions

exceptioncondition
ArgumentNullExceptionWhen stream or slides parameter is null.
ArgumentOutOfRangeExceptionWhen slides parameter contains wrong page numbers.
InvalidOperationExceptionWhen an unsupported SaveFormat is used, e.g. PPTX, PPTM, PPSX, PPSM, POTX, POTM, PPT, ODP.

See Also


Save(string, int[], SaveFormat, ISaveOptions)

Saves specified slides of a presentation to a file with the specified format with page number keeping.

public void Save(string fname, int[] slides, SaveFormat format, ISaveOptions options)
ParameterTypeDescription
fnameStringPath to the created file.
slidesInt32[]Array with slide positions, starting from 1.
formatSaveFormatFormat of the exported data.
optionsISaveOptionsAdditional format options.

See Also


Save(Stream, int[], SaveFormat)

Saves specified slides of a presentation to a stream in the specified format with page number keeping.

public void Save(Stream stream, int[] slides, SaveFormat format)
ParameterTypeDescription
streamStreamOutput stream.
slidesInt32[]Array with slide positions, starting from 1.
formatSaveFormatFormat of the exported data.

See Also


Save(Stream, int[], SaveFormat, ISaveOptions)

Saves specified slides of a presentation to a stream in the specified format with page number keeping.

public void Save(Stream stream, int[] slides, SaveFormat format, ISaveOptions options)
ParameterTypeDescription
streamStreamOutput stream.
slidesInt32[]Array with slide positions, starting from 1.
formatSaveFormatFormat of the exported data.
optionsISaveOptionsAdditional format options.

Exceptions

exceptioncondition
ArgumentNullExceptionWhen stream or slides parameter is null.
ArgumentOutOfRangeExceptionWhen slides parameter contains wrong page numbers.
InvalidOperationExceptionWhen an unsupported SaveFormat is used, e.g. PPTX, PPTM, PPSX, PPSM, POTX, POTM, PPT, ODP.

Examples

The following example shows how to convert PowerPoint to PNG.

[C#]
using (Presentation pres = new Presentation("pres.pptx"))
{
    for (var index = 0; index < pres.Slides.Count; index++)
    {
        ISlide slide = pres.Slides[index];
        slide.GetThumbnail().Save($"slide_{index}.png", ImageFormat.Png);
    }
}

The following example shows how to convert PowerPoint to PNG with custom dimensions.

[C#]
using (Presentation pres = new Presentation("pres.pptx"))
{
    float scaleX = 2f;
    float scaleY = 2f;
    for (var index = 0; index < pres.Slides.Count; index++)
    {
        ISlide slide = pres.Slides[index];
        slide.GetThumbnail(scaleX, scaleY).Save($"slide_{index}.png", ImageFormat.Png);
    }
}

The following example shows how to convert PowerPoint to PNG with custom size.

[C#]
using (Presentation pres = new Presentation("pres.pptx"))
{
    Size size = new Size(960, 720);
    for (var index = 0; index < pres.Slides.Count; index++)
    {
        ISlide slide = pres.Slides[index];
        slide.GetThumbnail(size).Save($"slide_{index}.png", ImageFormat.Png);
    }
}

See Also