Class Presentation

Class Presentation

Namespace: Aspose.Slides
Assembly: Aspose.Slides.dll (25.12.0)

Represents a Microsoft PowerPoint presentation.

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("43247d92-4bb9-4883-b807-4b77b186c741")]
public sealed class Presentation

Inheritance

object Presentation

Examples

The following example shows how to create PowerPoint Presentation.

// Instantiate a Presentation object that represents a presentation file
using (Presentation presentation = new Presentation())
{
    // Get the first slide
    ISlide slide = presentation.Slides[0];
    // Add an autoshape of type line
    slide.Shapes.AddAutoShape(ShapeType.Line, 50, 150, 300, 0);
	// Save the presentation file.
    presentation.Save("NewPresentation_out.pptx", SaveFormat.Pptx);
}

The following example shows how to open and save Presentation.

// Load any supported file in Presentation e.g. ppt, pptx, odp etc.
using (Presentation presentation = new Presentation("Sample.odp"))
{
	// Save the presentation file.
	presentation.Save("OutputPresenation.pptx", SaveFormat.Pptx);
}

Constructors

Presentation()

This constructor creates new presentation from scratch. Created presentation has one empty slide.

public Presentation()

Presentation(LoadOptions)

This constructor creates new presentation from scratch. Created presentation has one empty slide.

public Presentation(LoadOptions loadOptions)

Parameters

loadOptions LoadOptions

Additional load options.

Presentation(Stream)

This constructor is the primary mechanism for reading an existing Presentation.

public Presentation(Stream stream)

Parameters

stream Stream

Input stream.

Examples

FileStream fis = new FileStream("demo.pptx", FileMode.Open, FileAccess.Read);
Presentation pres = new Presentation(fis);
fis.Close();
Dim fis As FileStream = New FileStream("demo.pptx", FileMode.Open, FileAccess.Read)
Dim pres As Presentation = New Presentation(fis)
fis.Close()

Presentation(Stream, LoadOptions)

This constructor is the primary mechanism for reading an existing Presentation.

public Presentation(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

Input stream.

loadOptions LoadOptions

Additional load options.

Presentation(string)

This constructor gets a source file path from which the contents of the Presentation are read.

public Presentation(string file)

Parameters

file string

Input file.

Examples

Presentation pres = new Presentation("demo.pptx");
Dim pres As Presentation = New Presentation("demo.pptx")

Exceptions

ArgumentException

Thrown when input file has zero length

Presentation(string, LoadOptions)

This constructor gets a source file path from which the contents of the Presentation are read.

public Presentation(string file, LoadOptions loadOptions)

Parameters

file string

Input file.

loadOptions LoadOptions

Additional load options.

Exceptions

ArgumentException

Thrown when input file has zero length

Properties

AllCustomXmlParts

Returns all custom data parts in the presentaion. Read-only Aspose.Slides.ICustomXmlPart[].

public ICustomXmlPart[] AllCustomXmlParts { get; }

Property Value

ICustomXmlPart []

Examples

The following examples show how to clear all custom xml parts from PowerPoint Presentation.

using (Presentation pres = new Presentation("PresentationWithCustomXml.pptx"))
{
	// Iterate all custom XML Parts
    foreach (ICustomXmlPart item in pres.AllCustomXmlParts)
    {
        item.Remove();
    }
    pres.Save("out.pptx", SaveFormat.Pptx);
}

Audios

Returns the collection of all embedded audio files in the presentation. Read-only Aspose.Slides.IAudioCollection.

public IAudioCollection Audios { get; }

Property Value

IAudioCollection

Examples

The following examples shows how to add a hyperlink to an audio file.

using (Presentation pres = new Presentation())
{
    IAudio audio = pres.Audios.AddAudio(File.ReadAllBytes("audio.mp3"));
    IAudioFrame audioFrame = pres.Slides[0].Shapes.AddAudioFrameEmbedded(10, 10, 100, 100, audio);
    audioFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/");
    audioFrame.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs";
    pres.Save("pres-out.pptx", SaveFormat.Pptx);
}

CommentAuthors

Returns the collection of comments autors. Read-only Aspose.Slides.ICommentAuthorCollection.

public ICommentAuthorCollection CommentAuthors { get; }

Property Value

ICommentAuthorCollection

CurrentDateTime

Returns or sets date and time which will substitute content of datetime fields. Time of this Presentation object creation by default. Read/write System.DateTime.

public DateTime CurrentDateTime { get; set; }

Property Value

DateTime

CustomData

Returns the presentation’s custom data. Read-only Aspose.Slides.ICustomData.

public ICustomData CustomData { get; }

Property Value

ICustomData

DefaultTextStyle

Returns default text style for shapes. Read-only Aspose.Slides.ITextStyle.

public ITextStyle DefaultTextStyle { get; }

Property Value

ITextStyle

DigitalSignatures

Returns the collection of signatures used to sign the presentation. Read-only Aspose.Slides.IDigitalSignatureCollection.

public IDigitalSignatureCollection DigitalSignatures { get; }

Property Value

IDigitalSignatureCollection

Examples

using (Presentation pres = new Presentation("SomePresentationSigned.pptx"))
{
    if (pres.DigitalSignatures.Count > 0)
    {
        bool allSignaturesAreValid = true;

        Console.WriteLine("Signatures used to sign the presentation: ");
        foreach (DigitalSignature signature in pres.DigitalSignatures)
        {
            Console.WriteLine(signature.Certificate.SubjectName.Name + ", "
                    + signature.SignTime.ToString("yyyy-MM-dd HH:mm") + " -- " + (signature.IsValid ? "VALID" : "INVALID"));
            allSignaturesAreValid &= signature.IsValid;
        }

        if (allSignaturesAreValid)
            Console.WriteLine("Presentation is genuine, all signatures are valid.");
        else
            Console.WriteLine("Presentation has been modified since signing.");
    }
}

DocumentProperties

Returns DocumentProperties object which contains standard and custom document properties. Read-only Aspose.Slides.IDocumentProperties.

public IDocumentProperties DocumentProperties { get; }

Property Value

IDocumentProperties

FirstSlideNumber

Represents the first slide number in the presentation

public int FirstSlideNumber { get; set; }

Property Value

int

FontsManager

Returns fonts manager. Read-only Aspose.Slides.IFontsManager.

public IFontsManager FontsManager { get; }

Property Value

IFontsManager

Examples

The following example shows how to add embedded fonts to PowerPoint Presentation.

// Load presentation
using (Presentation presentation = new Presentation("Fonts.pptx"))
{
	// Load source font to be replaced
	IFontData sourceFont = new FontData("Arial");
	IFontData[] allFonts = presentation.FontsManager.GetFonts();
	IFontData[] embeddedFonts = presentation.FontsManager.GetEmbeddedFonts();
	foreach (IFontData font in allFonts)
	{
		if (!embeddedFonts.Contains(font))
		{
			presentation.FontsManager.AddEmbeddedFont(font, EmbedFontCharacters.All);
		}
	}
	// Save the presentation
	presentation.Save("AddEmbeddedFont_out.pptx", SaveFormat.Pptx);
}

HeaderFooterManager

Returns actual HeaderFooter manager. Read-only Aspose.Slides.IPresentationHeaderFooterManager.

public IPresentationHeaderFooterManager HeaderFooterManager { get; }

Property Value

IPresentationHeaderFooterManager

Examples

The following example shows how to set footer visibility inside Slide of PowerPoint Presentation.

using (Presentation presentation = new Presentation("presentation.ppt"))
{
    IBaseSlideHeaderFooterManager headerFooterManager = presentation.Slides[0].HeaderFooterManager;
	// Property IsFooterVisible is used for indicating that a slide footer placeholder is not present.
    if (!headerFooterManager.IsFooterVisible)
    {
		// Method SetFooterVisibility is used for making a slide footer placeholder visible.
        headerFooterManager.SetFooterVisibility(true);
    }
	// Property IsSlideNumberVisible is used for indicating that a slide page number placeholder is not present.
    if (!headerFooterManager.IsSlideNumberVisible)
    {
		// Method SetSlideNumberVisibility is used for making a slide page number placeholder visible.
        headerFooterManager.SetSlideNumberVisibility(true);
    }
	// Property IsDateTimeVisible is used for indicating that a slide date-time placeholder is not present.
    if (!headerFooterManager.IsDateTimeVisible)
    {
		// Method SetFooterVisibility is used for making a slide date-time placeholder visible.
        headerFooterManager.SetDateTimeVisibility(true);
    }
	// Method SetFooterText is used for setting text to slide footer placeholder.
    headerFooterManager.SetFooterText("Footer text");
	// Method SetDateTimeText is used for setting text to slide date-time placeholder.
    headerFooterManager.SetDateTimeText("Date and time text");
	presentation.Save("Presentation.ppt",SaveFormat.ppt);
}

The following example shows how to set child footer visibility inside Slide.

using (Presentation presentation = new Presentation("presentation.ppt"))
{
    IMasterSlideHeaderFooterManager headerFooterManager = presentation.Masters[0].HeaderFooterManager;
	// Method SetFooterAndChildFootersVisibility is used for making a master slide and all child footer placeholders visible.
    headerFooterManager.SetFooterAndChildFootersVisibility(true);
	// Method SetSlideNumberAndChildSlideNumbersVisibility is used for making a master slide and all child page number placeholders visible.
    headerFooterManager.SetSlideNumberAndChildSlideNumbersVisibility(true);
	// Method SetDateTimeAndChildDateTimesVisibility is used for making a master slide and all child date-time placeholders visible.
    headerFooterManager.SetDateTimeAndChildDateTimesVisibility(true);
	// Method SetFooterAndChildFootersText is used for setting text to master slide and all child footer placeholders.
    headerFooterManager.SetFooterAndChildFootersText("Footer text");
	// Method SetDateTimeAndChildDateTimesText is used for setting text to master slide and all child date-time placeholders.
    headerFooterManager.SetDateTimeAndChildDateTimesText("Date and time text");
}

HyperlinkQueries

Provides easy access to all hyperlinks contained in all presentation slides (not in master, layout, notes slides). Read-only Aspose.Slides.IHyperlinkQueries.

public IHyperlinkQueries HyperlinkQueries { get; }

Property Value

IHyperlinkQueries

Images

Returns the collection of all images in the presentation. Read-only Aspose.Slides.IImageCollection.

public IImageCollection Images { get; }

Property Value

IImageCollection

Examples

The following examples shows how to add image as BLOB in PowerPoint Presentation.

string pathToLargeImage = "large_image.jpg";
// creates a new presentation to which the image will be added.
using (Presentation pres = new Presentation())
{
	using (FileStream fileStream = new FileStream(pathToLargeImage, FileMode.Open))
	{
		// Let's add the image to the presentation - we choose KeepLocked behavior because we do
		// NOT intend to access the "largeImage.png" file.
		IPPImage img = pres.Images.AddImage(fileStream, LoadingStreamBehavior.KeepLocked);
		pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, 300, 200, img);
		// Saves the presentation. While a large presentation gets outputted, the memory consumption
		// stays low through the pres object's lifecycle
		pres.Save("presentationWithLargeImage.pptx", SaveFormat.Pptx);
	}
}

The following examples add a hyperlink to an image in a PowerPoint Presentation.

using (Presentation pres = new Presentation())
{
    // Adds image to presentation
    IPPImage image = pres.Images.AddImage(File.ReadAllBytes("image.png"));
    // Creates picture frame on slide 1 based on previously added image
    IPictureFrame pictureFrame = pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image);
    pictureFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/");
    pictureFrame.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs";
    pres.Save("pres-out.pptx", SaveFormat.Pptx);
}

LayoutSlides

Returns a list of all layout slides that are defined in the presentation. Read-only Aspose.Slides.IGlobalLayoutSlideCollection.

public IGlobalLayoutSlideCollection LayoutSlides { get; }

Property Value

IGlobalLayoutSlideCollection

Remarks

You can access to alternative API for adding/inserting/removing/cloning layout slides by using IMasterSlide.LayoutSlides property.

MasterHandoutSlideManager

Returns handout master manager. Read-only Aspose.Slides.IMasterHandoutSlideManager.

public IMasterHandoutSlideManager MasterHandoutSlideManager { get; }

Property Value

IMasterHandoutSlideManager

MasterNotesSlideManager

Returns notes master manager. Read-only Aspose.Slides.IMasterNotesSlideManager.

public IMasterNotesSlideManager MasterNotesSlideManager { get; }

Property Value

IMasterNotesSlideManager

MasterTheme

Returns master theme. Read-only Aspose.Slides.Theme.IMasterTheme.

public IMasterTheme MasterTheme { get; }

Property Value

IMasterTheme

Examples

The following examples shows how to change a theme effect by altering parts of elements of PowerPoint Presentation.

//Instantiate a presentation object that represents a presentation file
using (Presentation pres = new Presentation("Subtle_Moderate_Intense.pptx"))
{
    pres.MasterTheme.FormatScheme.LineStyles[0].FillFormat.SolidFillColor.Color = Color.Red;
    pres.MasterTheme.FormatScheme.FillStyles[2].FillType = FillType.Solid;
    pres.MasterTheme.FormatScheme.FillStyles[2].SolidFillColor.Color = Color.ForestGreen;
    pres.MasterTheme.FormatScheme.EffectStyles[2].EffectFormat.OuterShadowEffect.Distance = 10f;
    pres.Save("Design_04_Subtle_Moderate_Intense-out.pptx", SaveFormat.Pptx);
}

Masters

Returns a list of all master slides that are defined in the presentation. Read-only Aspose.Slides.IMasterSlideCollection.

public IMasterSlideCollection Masters { get; }

Property Value

IMasterSlideCollection

Examples

The following examples shows how to adding Images to Master Slides of PowerPoint Presentation.

using (Presentation pres = new Presentation())
{
    ISlide slide = pres.Slides[0];
    IMasterSlide masterSlide = slide.LayoutSlide.MasterSlide;
    IPPImage image = pres.Images.AddImage(File.ReadAllBytes("image.png"));
    masterSlide.Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image);
    pres.Save("pres.pptx", SaveFormat.Pptx);
}

The following examples shows how to change the background color of the master slide of PowerPoint Presentation.

// Instantiate the Presentation class that represents the presentation file
using (Presentation pres = new Presentation())
{
    // Set the background color of the Master ISlide to Forest Green
    pres.Masters[0].Background.Type = BackgroundType.OwnBackground;
    pres.Masters[0].Background.FillFormat.FillType = FillType.Solid;
    pres.Masters[0].Background.FillFormat.SolidFillColor.Color = Color.ForestGreen;
    // Write the presentation to disk
    pres.Save("SetSlideBackgroundMaster_out.pptx", SaveFormat.Pptx);
}

The following examples shows how to add slide layout to PowerPoint Presentation.

// Instantiate Presentation class that represents the presentation file
using (Presentation presentation = new Presentation("AccessSlides.pptx"))
{
    // Try to search by layout slide type
    IMasterLayoutSlideCollection layoutSlides = presentation.Masters[0].LayoutSlides;
    ILayoutSlide layoutSlide = layoutSlides.GetByType(SlideLayoutType.TitleAndObject) ?? layoutSlides.GetByType(SlideLayoutType.Title);
    if (layoutSlide == null)
    {
        // The situation when a presentation doesn't contain some type of layouts.
        // presentation File only contains Blank and Custom layout types.
        // But layout slides with Custom types has different slide names,
        // like "Title", "Title and Content", etc. And it is possible to use these
        // names for layout slide selection.
        // Also it is possible to use the set of placeholder shape types. For example,
        // Title slide should have only Title pleceholder type, etc.
        foreach (ILayoutSlide titleAndObjectLayoutSlide in layoutSlides)
        {
            if (titleAndObjectLayoutSlide.Name == "Title and Object")
            {
                layoutSlide = titleAndObjectLayoutSlide;
                break;
            }
        }
        if (layoutSlide == null)
        {
            foreach (ILayoutSlide titleLayoutSlide in layoutSlides)
            {
                if (titleLayoutSlide.Name == "Title")
                {
                    layoutSlide = titleLayoutSlide;
                    break;
                }
            }
            if (layoutSlide == null)
            {
                layoutSlide = layoutSlides.GetByType(SlideLayoutType.Blank);
                if (layoutSlide == null)
                {
                    layoutSlide = layoutSlides.Add(SlideLayoutType.TitleAndObject, "Title and Object");
                }
            }
        }
    }
    // Adding empty slide with added layout slide
    presentation.Slides.InsertEmptySlide(0, layoutSlide);
    // Save presentation
    presentation.Save("AddLayoutSlides_out.pptx", SaveFormat.Pptx);
}

NotesSize

Returns notes slide size object. Read-only Aspose.Slides.INotesSize.

public INotesSize NotesSize { get; }

Property Value

INotesSize

ProtectionManager

Gets manager of the permissions for this presentation. Read-only Aspose.Slides.IProtectionManager.

public IProtectionManager ProtectionManager { get; }

Property Value

IProtectionManager

Sections

Returns a list of all slides sections that are defined in the presentation. Read-only Aspose.Slides.ISectionCollection.

public ISectionCollection Sections { get; }

Property Value

ISectionCollection

Examples

The following examples shows how to create Sections in a PowerPoint Presentation.

using (Presentation pres = new Presentation())
{
    ISlide defaultSlide = pres.Slides[0];
    ISlide newSlide1 = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);
    ISlide newSlide2 = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);
    ISlide newSlide3 = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);
    ISlide newSlide4 = pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);
    ISection section1 = pres.Sections.AddSection("Section 1", newSlide1);
	// section1 will be ended at newSlide2 and after it section2 will start
    ISection section2 = pres.Sections.AddSection("Section 2", newSlide3);
    pres.Save("pres-sections.pptx", SaveFormat.Pptx);
    pres.Sections.ReorderSectionWithSlides(section2, 0);
    pres.Save("pres-sections-moved.pptx", SaveFormat.Pptx);
    pres.Sections.RemoveSectionWithSlides(section2);
    pres.Sections.AppendEmptySection("Last empty section");
    pres.Save("pres-section-with-empty.pptx",SaveFormat.Pptx);
}

The following examples shows how to changing the names of Sections.

using (Presentation pres = new Presentation("pres.pptx"))
{
   ISection section = pres.Sections[0];
   section.Name = "My section";
}

SlideShowSettings

Returns the slide show settings for the presentation.

public SlideShowSettings SlideShowSettings { get; }

Property Value

SlideShowSettings

SlideSize

Returns slide size object. Read-only Aspose.Slides.ISlideSize.

public ISlideSize SlideSize { get; }

Property Value

ISlideSize

Examples

The following example shows how to change the slide size in a PowerPoint Presentation.

using (Presentation pres = new Presentation("pres-4x3-aspect-ratio.pptx"))
{
    pres.SlideSize.SetSize(SlideSizeType.OnScreen16x9, SlideSizeScaleType.DoNotScale);
    pres.Save("pres-4x3-aspect-ratio.pptx", SaveFormat.Pptx);
}

The following example shows how to set slide size with respect to content scaling for a PowerPoint Presentation.

// Instantiate a Presentation object that represents a presentation file
using(Presentation presentation = new Presentation("AccessSlides.pptx")) {
  using(Presentation auxPresentation = new Presentation()) {
    ISlide slide = presentation.Slides[0];
    // Set the slide size of generated presentations to that of source
    presentation.SlideSize.SetSize(540, 720, SlideSizeScaleType.EnsureFit); // Method SetSize is used for set slide size with scale content to ensure fit
    presentation.SlideSize.SetSize(SlideSizeType.A4Paper, SlideSizeScaleType.Maximize); // Method SetSize is used for set slide size with maximize size of content
    // Save Presentation to disk
    auxPresentation.Save("Set_Size&Type_out.pptx", SaveFormat.Pptx);
  }
}

The following example shows how to specifying custom slide sizes in a PowerPoint Presentation.

using (Presentation pres = new Presentation("pres.pptx"))
{
    pres.SlideSize.SetSize(780, 540, SlideSizeScaleType.DoNotScale); // A4 paper size
    pres.Save("pres-a4-slide-size.pptx", SaveFormat.Pptx);
}

Slides

Returns a list of all slides that are defined in the presentation. Read-only Aspose.Slides.ISlideCollection.

public ISlideCollection Slides { get; }

Property Value

ISlideCollection

Examples

The following example shows how to set slides’ background color of PowerPoint Presentation.

// Instantiate the Presentation class that represents the presentation file
using (Presentation pres = new Presentation())
{
    // Set the background color of the first ISlide to Blue
    pres.Slides[0].Background.Type = BackgroundType.OwnBackground;
    pres.Slides[0].Background.FillFormat.FillType = FillType.Solid;
    pres.Slides[0].Background.FillFormat.SolidFillColor.Color = Color.Blue;
    pres.Save("ContentBG_out.pptx", SaveFormat.Pptx);
}

The following example shows how to set slides’ background image of PowerPoint Presentation.

// Instantiate the Presentation class that represents the presentation file
using (Presentation pres = new Presentation("SetImageAsBackground.pptx"))
{
    // Set the background with Image
    pres.Slides[0].Background.Type = BackgroundType.OwnBackground;
    pres.Slides[0].Background.FillFormat.FillType = FillType.Picture;
    pres.Slides[0].Background.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
    // Set the picture
    System.Drawing.Image img = (System.Drawing.Image)new Bitmap(dataDir + "Tulips.jpg");
    // Add image to presentation's images collection
    IPPImage imgx = pres.Images.AddImage(img);
    pres.Slides[0].Background.FillFormat.PictureFillFormat.Picture.Image = imgx;
    // Write the presentation to disk
    pres.Save("ContentBG_Img_out.pptx", SaveFormat.Pptx);
}

The following example shows how to add slide transition Presentation.

// Instantiate Presentation class to load the source presentation file
using (Presentation presentation = new Presentation("AccessSlides.pptx"))
{
    // Apply circle type transition on slide 1
    presentation.Slides[0].SlideShowTransition.Type = TransitionType.Circle;
    // Apply comb type transition on slide 2
    presentation.Slides[1].SlideShowTransition.Type = TransitionType.Comb;
    // Write the presentation to disk
    presentation.Save("SampleTransition_out.pptx", SaveFormat.Pptx);
}

The following example shows how to add advanced slide Transition.

// Instantiate Presentation class that represents a presentation file
using (Presentation pres = new Presentation("BetterSlideTransitions.pptx"))
{
    // Apply circle type transition on slide 1
    pres.Slides[0].SlideShowTransition.Type = TransitionType.Circle;
    // Set the transition time of 3 seconds
    pres.Slides[0].SlideShowTransition.AdvanceOnClick = true;
    pres.Slides[0].SlideShowTransition.AdvanceAfterTime = 3000;
    // Apply comb type transition on slide 2
    pres.Slides[1].SlideShowTransition.Type = TransitionType.Comb;
    // Set the transition time of 5 seconds
    pres.Slides[1].SlideShowTransition.AdvanceOnClick = true;
    pres.Slides[1].SlideShowTransition.AdvanceAfterTime = 5000;
    // Apply zoom type transition on slide 3
    pres.Slides[2].SlideShowTransition.Type = TransitionType.Zoom;
    // Set the transition time of 7 seconds
    pres.Slides[2].SlideShowTransition.AdvanceOnClick = true;
    pres.Slides[2].SlideShowTransition.AdvanceAfterTime = 7000;
    // Write the presentation to disk
    pres.Save("SampleTransition_out.pptx", SaveFormat.Pptx);
}

SourceFormat

Returns information about from which format presentation was loaded. Read-only Aspose.Slides.SourceFormat.

public SourceFormat SourceFormat { get; }

Property Value

SourceFormat

VbaProject

Gets or sets VBA project with presentation macros. Read/write Aspose.Slides.Vba.IVbaProject.

public IVbaProject VbaProject { get; set; }

Property Value

IVbaProject

Videos

Returns the collection of all embedded video files in the presentation. Read-only Aspose.Slides.IVideoCollection.

public IVideoCollection Videos { get; }

Property Value

IVideoCollection

Examples

The following examples shows how to create embedded Video Frame in a PowerPoint Presentation.

// Instantiate Presentation class that represents the PPTX
using (Presentation pres = new Presentation())
{
    // Get the first slide
    ISlide sld = pres.Slides[0];
    // Embedd vide inside presentation
    IVideo vid = pres.Videos.AddVideo(new FileStream("Wildlife.mp4", FileMode.Open));
    // Add Video Frame
    IVideoFrame vf = sld.Shapes.AddVideoFrame(50, 150, 300, 350, vid);
    // Set video to Video Frame
    vf.EmbeddedVideo = vid;
    // Set Play Mode and Volume of the Video
    vf.PlayMode = VideoPlayModePreset.Auto;
    vf.Volume = AudioVolumeMode.Loud;
    // Write the PPTX file to disk
    pres.Save("VideoFrame_out.pptx", SaveFormat.Pptx);
}

The following examples shows how to add a video passing path to the video file directly into AddVideoFrame method for PowerPoint Presentation.

using (Presentation pres = new Presentation())
{
    ISlide sld = pres.Slides[0];
    IVideoFrame vf = sld.Shapes.AddVideoFrame(50, 150, 300, 150, "video1.avi");
}

The following examples shows how to add large file through BLOB to a Presentation.

const string pathToVeryLargeVideo = "veryLargeVideo.avi";
// Creates a new presentation to which the video will be added
using (Presentation pres = new Presentation())
{
    using (FileStream fileStream = new FileStream(pathToVeryLargeVideo, FileMode.Open))
    {
        // Let's add the video to the presentation - we chose the KeepLocked behavior because we do
        //not intend to access the "veryLargeVideo.avi" file.
        IVideo video = pres.Videos.AddVideo(fileStream, LoadingStreamBehavior.KeepLocked);
        pres.Slides[0].Shapes.AddVideoFrame(0, 0, 480, 270, video);
        // Saves the presentation. While a large presentation gets outputted, the memory consumption
        // stays low through the pres object's lifecycle
        pres.Save("presentationWithLargeVideo.pptx", SaveFormat.Pptx);
    }
}

The following examples shows how to export large file through BLOB from PowerPoint Presentation.

const string hugePresentationWithAudiosAndVideosFile = @"Large  Video File Test1.pptx";
LoadOptions loadOptions = new LoadOptions
{
	BlobManagementOptions = {
		// Locks the source file and does NOT load it into memory
		PresentationLockingBehavior = PresentationLockingBehavior.KeepLocked,
	}
};
// Creates a Presentation's instance, locks the "hugePresentationWithAudiosAndVideos.pptx" file.
using (Presentation pres = new Presentation(hugePresentationWithAudiosAndVideosFile, loadOptions))
{
	// Let's save each video to a file. To prevent high memory usage, we need a buffer that will be used
	// to transfer the data from the presentation's video stream to a stream for a newly created video file.
	byte[] buffer = new byte[8 * 1024];
	// Iterates through the videos
	for (var index = 0; index < pres.Videos.Count; index++)
	{
		IVideo video = pres.Videos[index];
		// Opens the presentation video stream. Please, note that we intentionally avoided accessing properties
		// like video.BinaryData - because this property returns a byte array containing a full video, which then
		// causes bytes to be loaded into memory. We use video.GetStream, which will return Stream - and does NOT
		//  require us to load the whole video into the memory.
		using (Stream presVideoStream = video.GetStream())
		{
			using (FileStream outputFileStream = File.OpenWrite($"video{index}.avi"))
			{
				int bytesRead;
				while ((bytesRead = presVideoStream.Read(buffer, 0, buffer.Length)) > 0)
				{
					outputFileStream.Write(buffer, 0, bytesRead);
				}
			}
		}
		// Memory consumption will remain low regardless of the size of the video or presentation,
	}
	// If necessary, you can apply the same steps for audio files.
}

The following examples shows how to add a hyperlink to a video in a PowerPoint Presentation.

using (Presentation pres = new Presentation())
{
    IVideo video = pres.Videos.AddVideo(File.ReadAllBytes("video.avi"));
    IVideoFrame videoFrame = pres.Slides[0].Shapes.AddVideoFrame(10, 10, 100, 100, video);
    videoFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/");
    videoFrame.HyperlinkClick.Tooltip = "More than 70% Fortune 100 companies trust Aspose APIs";
    pres.Save("pres-out.pptx", SaveFormat.Pptx);
}

The following examples shows how to create Video Frame with Video from Web Source in a PowerPoint Presentation.

public static void Run()
{
    using (Presentation pres = new Presentation())
    {
        AddVideoFromYouTube(pres, "Tj75Arhq5ho");
        pres.Save("AddVideoFrameFromWebSource_out.pptx", SaveFormat.Pptx);
    }
}
private static void AddVideoFromYouTube(Presentation pres, string videoId)
{
    //add videoFrame
    IVideoFrame videoFrame = pres.Slides[0].Shapes.AddVideoFrame(10, 10, 427, 240, "https://www.youtube.com/embed/" + videoId);
    videoFrame.PlayMode = VideoPlayModePreset.Auto;
    //load thumbnail
    using (WebClient client = new WebClient())
    {
        string thumbnailUri = "http://img.youtube.com/vi/" + videoId + "/hqdefault.jpg";
        videoFrame.PictureFormat.Picture.Image = pres.Images.AddImage(client.DownloadData(thumbnailUri));
    }
}

The following examples shows how to extract Video from slide of PowerPoint Presentation.

// Instantiate a Presentation object that represents a presentation file
using (Presentation presentation = new Presentation("Video.pptx"))
{
	foreach (ISlide slide in presentation.Slides)
	{
		foreach (IShape shape in presentation.Slides[0].Shapes)
		{
			if (shape is VideoFrame)
			{
				IVideoFrame vf = shape as IVideoFrame;
				String type = vf.EmbeddedVideo.ContentType;
				int ss = type.LastIndexOf('/');
				type = type.Remove(0, type.LastIndexOf('/') + 1);
				Byte[] buffer = vf.EmbeddedVideo.BinaryData;
				using (FileStream stream = new FileStream("NewVideo_out." + type, FileMode.Create, FileAccess.Write, FileShare.Read))
				{
					stream.Write(buffer, 0, buffer.Length);
				}
			}
		}
	}
}

ViewProperties

Gets presentation wide view properties. Read-only Aspose.Slides.IViewProperties.

public IViewProperties ViewProperties { get; }

Property Value

IViewProperties

Methods

Dispose()

Releases all resources used by this Presentation object.

public void Dispose()

~Presentation()

Finalizes this Presentation object.

protected ~Presentation()

GetImages(IRenderingOptions)

Returns a Image objects for all slides of a presentation.

public IImage[] GetImages(IRenderingOptions options)

Parameters

options IRenderingOptions

Tiff options.

Returns

IImage []

Image objects.

GetImages(IRenderingOptions, int[])

Returns a Thumbnail Image objects for specified slides of a presentation.

public IImage[] GetImages(IRenderingOptions options, int[] slides)

Parameters

options IRenderingOptions

Tiff options.

slides int []

Array with slide positions, starting from 1.

Returns

IImage []

Image objects.

GetImages(IRenderingOptions, float, float)

Returns a Thumbnail Image objects for all slides of a presentation with custom scaling.

public IImage[] GetImages(IRenderingOptions options, float scaleX, float scaleY)

Parameters

options IRenderingOptions

Tiff options.

scaleX float

The value by which to scale this Thumbnail in the x-axis direction.

scaleY float

The value by which to scale this Thumbnail in the y-axis direction.

Returns

IImage []

Image objects.

GetImages(IRenderingOptions, int[], float, float)

Returns a Thumbnail Image objects for specified slides of a presentation with custom scaling.

public IImage[] GetImages(IRenderingOptions options, int[] slides, float scaleX, float scaleY)

Parameters

options IRenderingOptions

Tiff options.

slides int []

Array with slide positions, starting from 1.

scaleX float

The value by which to scale this Thumbnail in the x-axis direction.

scaleY float

The value by which to scale this Thumbnail in the y-axis direction.

Returns

IImage []

Image objects.

GetImages(IRenderingOptions, Size)

Returns a Thumbnail Image objects for all slides of a presentation with specified size.

public IImage[] GetImages(IRenderingOptions options, Size imageSize)

Parameters

options IRenderingOptions

Tiff options.

imageSize Size

Size of the image to create.

Returns

IImage []

Image objects.

GetImages(IRenderingOptions, int[], Size)

Returns a Thumbnail Image objects for specified slides of a presentation with specified size.

public IImage[] GetImages(IRenderingOptions options, int[] slides, Size imageSize)

Parameters

options IRenderingOptions

Tiff options.

slides int []

Array with slide positions, starting from 1.

imageSize Size

Size of the image to create.

Returns

IImage []

Image objects.

GetSlideById(uint)

Returns a Slide, MasterSlide or LayoutSlide by Id.

public IBaseSlide GetSlideById(uint id)

Parameters

id uint

Id of a slide.

Returns

IBaseSlide

IBaseSlide object.

HighlightRegex(Regex, Color, IFindResultCallback)

Highlights all matches of the regular expression with the specified color.

public void HighlightRegex(Regex regex, Color highlightColor, IFindResultCallback callback)

Parameters

regex Regex

The regular expression System.Text.RegularExpressions.Regex to get strings to highlight.

highlightColor Color

The color to highlight the text.

callback IFindResultCallback

The callback object for receiving search results Aspose.Slides.IFindResultCallback.

Examples

The following code sample shows how to highlight text in a PowerPoint Presentation using a regular expression.

using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	Regex regex = new Regex(@"\b[^\s]{10,}\b");
	// highlighting all words with 10 or more characters
	presentation.HighlightRegex(regex, Color.Blue, null);
	presentation.Save("SomePresentation-out.pptx", SaveFormat.Pptx);
}

HighlightText(string, Color)

Highlights all matches of the sample text with the specified color.

public void HighlightText(string text, Color highlightColor)

Parameters

text string

The text to highlight.

highlightColor Color

The color to highlight the text.

Examples

The following code sample shows how to highlight text in a PowerPoint presentation.

using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	// highlighting all separate 'the' occurrences
	presentation.HighlightText("the", Color.Violet);
	presentation.Save("SomePresentation-out2.pptx", SaveFormat.Pptx);
}

HighlightText(string, Color, ITextSearchOptions, IFindResultCallback)

Highlights all matches of the sample text with the specified color.

public void HighlightText(string text, Color highlightColor, ITextSearchOptions options, IFindResultCallback callback)

Parameters

text string

The text to highlight.

highlightColor Color

The color to highlight the text.

options ITextSearchOptions

Text search options Aspose.Slides.ITextSearchOptions.

callback IFindResultCallback

The callback object for receiving search results Aspose.Slides.IFindResultCallback.

Examples

The following code sample shows how to highlight text in a PowerPoint presentation.

using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	// highlighting all separate 'the' occurrences
	presentation.HighlightText("the", Color.Violet, new TextSearchOptions() {WholeWordsOnly = true}, null);
	presentation.Save("SomePresentation-out2.pptx", SaveFormat.Pptx);
}

JoinPortionsWithSameFormatting()

Joins runs with same formatting in all paragraphs in all acceptable shapes in all slides.

public void JoinPortionsWithSameFormatting()

ReplaceRegex(Regex, string, IFindResultCallback)

Replaces all matches of the regular expression with the specified string.

public void ReplaceRegex(Regex regex, string newText, IFindResultCallback callback)

Parameters

regex Regex

The regular expression System.Text.RegularExpressions.Regex to get strings to replace.

newText string

The string to replace all occurrences of the strings to be replaced.

callback IFindResultCallback

The callback object for receiving search results Aspose.Slides.IFindResultCallback.

Examples

The following code sample shows how to replace text using regular expression with the specified string.

using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	Regex regex = new Regex(@"\b[^\s]{10,}\b");
	// Replace all words with 10 or more characters with '***'
	presentation.ReplaceRegex(regex, "***", null);
	presentation.Save("SomePresentation-out.pptx", SaveFormat.Pptx);
}

ReplaceText(string, string, ITextSearchOptions, IFindResultCallback)

Replaces all occurrences of the specified text with another specified text.

public void ReplaceText(string oldText, string newText, ITextSearchOptions options, IFindResultCallback callback)

Parameters

oldText string

The string to be replaced.

newText string

The string to replace all occurrences of oldText.

options ITextSearchOptions

Text search options Aspose.Slides.ITextSearchOptions.

callback IFindResultCallback

The callback object for receiving search results Aspose.Slides.IFindResultCallback.

Examples

The following sample code shows how to replace one specified string with another specified string.

using (Presentation presentation = new Presentation("SomePresentation.pptx"))
{
	// Replace all separate 'the' occurrences with '***'
	presentation.ReplaceText("the", "***", new TextSearchOptions() {WholeWordsOnly = true}, null);
	presentation.Save("SomePresentation-out2.pptx", SaveFormat.Pptx);
}

Save(string, SaveFormat)

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

public void Save(string fname, SaveFormat format)

Parameters

fname string

Path to the created file.

format SaveFormat

Format of the exported data.

Save(Stream, SaveFormat)

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

public void Save(Stream stream, SaveFormat format)

Parameters

stream Stream

Output stream.

format SaveFormat

Format of the exported data.

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)

Parameters

fname string

Path to the created file.

format SaveFormat

Format of the exported data.

options ISaveOptions

Additional format options.

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)

Parameters

stream Stream

Output stream.

format SaveFormat

Format of the exported data.

options ISaveOptions

Additional format options.

Exceptions

NotSupportedException

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

Save(IXamlOptions)

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

public void Save(IXamlOptions options)

Parameters

options IXamlOptions

The XAML format options.

Examples

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

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)

Parameters

fname string

Path to the created file.

slides int []

Array with slide positions, starting from 1.

format SaveFormat

Format of the exported data.

Exceptions

ArgumentNullException

When stream or slides parameter is null.

ArgumentOutOfRangeException

When slides parameter contains wrong page numbers.

InvalidOperationException

When an unsupported SaveFormat is used, e.g. PPTX, PPTM, PPSX, PPSM, POTX, POTM, PPT, ODP.

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)

Parameters

fname string

Path to the created file.

slides int []

Array with slide positions, starting from 1.

format SaveFormat

Format of the exported data.

options ISaveOptions

Additional format options.

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)

Parameters

stream Stream

Output stream.

slides int []

Array with slide positions, starting from 1.

format SaveFormat

Format of the exported data.

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)

Parameters

stream Stream

Output stream.

slides int []

Array with slide positions, starting from 1.

format SaveFormat

Format of the exported data.

options ISaveOptions

Additional format options.

Examples

The following example shows how to convert PowerPoint to PNG.

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.

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.

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);
    }
}

Exceptions

ArgumentNullException

When stream or slides parameter is null.

ArgumentOutOfRangeException

When slides parameter contains wrong page numbers.

InvalidOperationException

When an unsupported SaveFormat is used, e.g. PPTX, PPTM, PPSX, PPSM, POTX, POTM, PPT, ODP.