Class Presentation
Represents the PowerPoint presentation.
Inheritance
Namespace: Syncfusion.Presentation
Assembly: Syncfusion.Presentation.NET.dll
Syntax
public sealed class Presentation : Object, IPresentation, IDisposable
Properties
BuiltInDocumentProperties
Gets an IBuiltInDocumentProperties instance. Read-only.
Declaration
public IBuiltInDocumentProperties BuiltInDocumentProperties { get; }
Property Value
Type |
---|
IBuiltInDocumentProperties |
Examples
//Create a presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Retrieve the built-in document property, it is read only
IBuiltInDocumentProperties builtin = presentation.BuiltInDocumentProperties;
//Set the application name
builtin.ApplicationName = "Essential Presentation";
//Save the presentation
presentation.Save("Sample.pptx");
//Close the presentation
presentation.Close();
'Create a presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Retrieve the built-in document property, it is read only
Dim builtin As IBuiltInDocumentProperties = presentation__1.BuiltInDocumentProperties
'Set the application name
builtin.ApplicationName = "Essential Presentation"
'Save the presentation
presentation__1.Save("Sample.pptx")
'Close the presentation
presentation__1.Close()
CustomDocumentProperties
Gets an ICustomDocumentProperties instance. Read-only.
Declaration
public ICustomDocumentProperties CustomDocumentProperties { get; }
Property Value
Type |
---|
ICustomDocumentProperties |
Examples
//Create a presentation.
IPresentation presentation = Presentation.Create();
//Retrieve the custom document property, it is read only
ICustomDocumentProperties custom = presentation.CustomDocumentProperties;
//Add custom document property
custom.Add("PropertyA");
//Set the boolean property
custom["PropertyA"].Boolean = true;
//Save the presentation
presentation.Save("Sample.pptx");
//Close the presentation
presentation.Close();
'Create a presentation.
Dim presentation__1 As IPresentation = Presentation.Create()
'Retrieve the custom document property, it is read only
Dim [custom] As ICustomDocumentProperties = presentation__1.CustomDocumentProperties
'Add custom document property
[custom].Add("PropertyA")
'Set the boolean property
[custom]("PropertyA").[Boolean] = True
'Save the presentation
presentation__1.Save("Sample.pptx")
'Close the presentation
presentation__1.Close()
Final
Gets or sets a value indicating whether the IPresentation instance is marked as final.
Declaration
public bool Final { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
//Create an instance for PowerPoint presentation
IPresentation pptxDoc = Presentation.Create();
//Add slide to the presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Mark the presentation as final
pptxDoc.Final = true;
//Save the presentation
pptxDoc.Save("Sample.pptx");
//Close the presentation
pptxDoc.Close();
'Create an instance for PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Create()
'Add slide to the presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Mark the presentation as final
pptxDoc.Final = True
'Save the presentation
pptxDoc.Save("Sample.pptx")
'Close the presentation
pptxDoc.Close()
FirstSlideNumber
Gets or sets the first slide number of the PowerPoint Presentation. The default value is 1.
Declaration
public int FirstSlideNumber { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
First slide number is the starting slide number of presentation, and this API allows to set the first slide number from 0 to 9999.
Examples
//Creates a new PowerPint Presentation.
using (IPresentation presentation = Presentation.Create())
{
//Sets the first slide number of the PowerPoint Presentation.
presentation.FirstSlideNumber = 5;
//Adds slide to the PowerPoint.
ISlide slide1 = presentation.Slides.Add(SlideLayoutType.TitleAndContent);
//Adds slide to the PowerPoint.
ISlide slide2 = presentation.Slides.Add(SlideLayoutType.TitleAndContent);
//Adds slide to the PowerPoint.
ISlide slide3 = presentation.Slides.Add(SlideLayoutType.TitleAndContent);
//Gets the first slide slidenumber.
int firstSlideNumber = slide1.SlideNumber;
//Gets the second slide slidenumber.
int secondSlideNumber = slide2.SlideNumber;
//Saves the PowerPoint Presentation.
presentation.Save("Output.pptx");
}
'Creates a PowerPoint instance
Using pptxDoc As IPresentation = Presentation.Create()
'Sets the first slide number of the PowerPoint Presentation.
pptxDoc.FirstSlideNumber = 5
'Adds a slide to the PowerPoint presentation
Dim slide1 As ISlide = pptxDoc.Slides.Add(SlideLayoutType.TitleAndContent)
'Adds a slide to the PowerPoint presentation
Dim slide2 As ISlide = pptxDoc.Slides.Add(SlideLayoutType.TitleAndContent)
'Adds a slide to the PowerPoint presentation
Dim slide3 As ISlide = pptxDoc.Slides.Add(SlideLayoutType.TitleAndContent)
'Gets the first slide slidenumber.
Dim firstSlideNumber As Integer = slide1.SlideNumber
'Gets the second slide slidenumber.
Dim secondSlideNumber As Integer = slide2.SlideNumber
'Saves the Presentation to the file system.
pptxDoc.Save("Output.pptx")
End Using
FontSettings
Gets the font settings. Read Only.
Declaration
public FontSettings FontSettings { get; }
Property Value
Type | Description |
---|---|
FontSettings | The font settings in the PowerPoint document. |
Examples
//Load the PowerPoint presentation and convert to image
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
// Initializes the 'SubstituteFont' event to set the replacement font
pptxDoc.FontSettings.InitializeFallbackFonts();
//Converts the first slide into image
Image image = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageType.Metafile);
//Close the presentation.
pptxDoc.Close();
'Load the PowerPoint presentation and convert to image
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
'Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault()
'Convert the PowerPoint presentation to image.
Dim image As Image = pptxDoc.Slides(0).ConvertToImage(Syncfusion.Drawing.ImageType.Metafile)
'Close the Presentation instance
pptxDoc.Close()
HasMacros
Gets or sets whether the presentation has macros.
Declaration
public bool HasMacros { get; }
Property Value
Type |
---|
System.Boolean |
Examples
//Opens an existing macro enabled PowerPoint presentation
IPresentation pptxDoc = Presentation.Open("Sample.PPTM");
//Checks whether the presentation has macros and then removes them
if (pptxDoc.HasMacros)
pptxDoc.RemoveMacros();
//Saves the presentation
pptxDoc.Save("Output.pptx");
//Closes the presentation
pptxDoc.Close();
'Opens an existing macro enabled PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Open("Sample.PPTM")
'Checks whether the presentation has macros and then removes them
If pptxDoc.HasMacros Then
pptxDoc.RemoveMacros()
End If
'Saves the presentation
pptxDoc.Save("Output.pptx")
'Closes the presentation
pptxDoc.Close()
IsWriteProtected
Gets whether the presentation is write Protected. Read-only.
Declaration
public bool IsWriteProtected { get; }
Property Value
Type |
---|
System.Boolean |
Examples
//Create an instance for presentation
IPresentation presentation = Presentation.Open("Sample.pptx");
//Check whether the presentation is write protected.
if (presentation.IsWriteProtected)
{
//Removes the write protection from presentation instance
presentation.RemoveWriteProtection();
}
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation.
presentation.Close();
'Create an instance for presentation
Dim presentation As IPresentation = Presentation.Open("Sample.pptx")
'Check whether the presentation is write protected.
if (presentation.IsWriteProtected)
{
'Removes the write protection from presentation instance
presentation.RemoveWriteProtection()
}
'Save the presentation
presentation.Save("Output.pptx")
'Close the presentation.
presentation.Close()
Masters
Gets the IMasterSlides collection of the IPresentation instance. Read-only.
Declaration
public IMasterSlides Masters { get; }
Property Value
Type |
---|
IMasterSlides |
Examples
//Create a new presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Retrieve the collection of layout Slide
IMasterSlides masterslides = presentation.Masters;
//Get a master by specifying the index in collection
IMasterSlide masterSlide = presentation.Masters[0];
//Add a group shape to master slide
masterSlide.GroupShapes.AddGroupShape(200,234,198,173);
//Add an autoshape - bevel to master slide
masterSlide.Shapes.AddShape(AutoShapeType.Bevel,237,45,187,120);
//Add master slide to the collection
masterslides.Add(masterSlide);
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Create a new presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Retrieve the collection of layout Slide
Dim masterslides As IMasterSlides = presentation__1.Masters
'Get a master by specifying the index in collection
Dim masterSlide As IMasterSlide = presentation__1.Masters(0)
'Add a group shape to master slide
masterSlide.GroupShapes.AddGroupShape(200, 234, 198, 173)
'Add an autoshape - bevel to master slide
masterSlide.Shapes.AddShape(AutoShapeType.Bevel, 237, 45, 187, 120)
'Add master slide to the collection
masterslides.Add(masterSlide)
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
PresentationRenderer
Represents the Slide to image converter instance for NetStandard.
Declaration
public IPresentationRenderer PresentationRenderer { get; set; }
Property Value
Type |
---|
IPresentationRenderer |
Remarks
This property is supported in NetStandard supported platforms only.
Sections
Returns a collection of ISection instances. Read-only.
Declaration
public ISections Sections { get; }
Property Value
Type |
---|
ISections |
Examples
//Creates a PowerPoint presentation
IPresentation presentation = Presentation.Create();
//Adds a section to the PowerPoint presentation
ISection section = presentation.Sections.Add();
//Sets a name to the created section
section.Name = "SectionDemo";
//Adds a slide to the created section
ISlide slide = section.AddSlide(SlideLayoutType.Blank);
//Adds a text box to the slide
slide.AddTextBox(10, 10, 100, 100).TextBody.AddParagraph("Slide in SectionDemo");
//Saves the PowerPoint presentation
presentation.Save("Sample.pptx");
//Close the presentation
presentation.Close();
'Creates a PowerPoint presentation
Dim presentation__1 As IPresentation = Presentation.Create()
'Adds a section to the PowerPoint presentation
Dim section As ISection = presentation__1.Sections.Add()
'Sets a name to the created section
section.Name = "SectionDemo"
'Adds a slide to the created section
Dim slide As ISlide = section.AddSlide(SlideLayoutType.Blank)
'Adds a text box to the slide
slide.AddTextBox(10, 10, 100, 100).TextBody.AddParagraph("Slide in SectionDemo")
'Saves the PowerPoint presentation
presentation__1.Save("Sample.pptx")
'Close the Presentation instance
presentation__1.Close()
Slides
Gets the slide collection of ISlides instance. Read-only.
Declaration
public ISlides Slides { get; }
Property Value
Type |
---|
ISlides |
Examples
//Create a new presentation.
IPresentation presentation = Presentation.Create();
//Create instance to hold the slide collection
ISlides slides = presentation.Slides;
//Add slide to presentation
slides.Add();
//Add a blank slide to the presentation.
slides.Add(SlideLayoutType.Blank);
//Add slide to the collection by passing the slide instance
slides.Add(slides.Add(SlideLayoutType.Title));
//Retrieve the specific slide item, read only
ISlide _slide = slides[0];
//Set the slide name
_slide.Name = "My Slide";
//Save the presentation
presentation.Save("Sample.pptx");
//Close the presentation
presentation.Close();
'Create a new presentation.
IPresentation presentation = Presentation.Create();
'Create instance to hold the slide collection
ISlides slides = presentation.Slides;
'Add slide to presentation
slides.Add();
'Add a blank slide to the presentation.
slides.Add(SlideLayoutType.Blank);
'Add slide to the collection by passing the slide instance
slides.Add(slides.Add(SlideLayoutType.Title));
'Retrieve the specific slide item, read only
ISlide _slide = slides[0];
'Set the slide name
slide.Name = "My Slide";
'Save the presentation
presentation.Save("Sample.pptx");
'Close the presentation
presentation.Close();
SlideSize
Gets the slide size of ISlideSize instance. Read-only.
Declaration
public ISlideSize SlideSize { get; }
Property Value
Type |
---|
ISlideSize |
Examples
//Create a presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Add a blank slide for the chart.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Retrieve the slides size, read only
ISlideSize slidesize = presentation.SlideSize;
//Set the slide orientation of presentation
slidesize.SlideOrientation = SlideOrientation.Landscape;
//Save the presentation
presentation.Save("Sample.pptx");
//Close the presentation
presentation.Close();
'Create a presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add a blank slide for the chart.
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Blank)
'Retrieve the slides size, read only
Dim slidesize As ISlideSize = presentation__1.SlideSize
'Set the slide orientation of presentation
slidesize.SlideOrientation = SlideOrientation.Landscape
'Save the presentation
presentation__1.Save("Sample.pptx")
'Close the presentation
presentation__1.Close()
Methods
Clone()
Creates an independent copy of IPresentation instance.
Declaration
public IPresentation Clone()
Returns
Type | Description |
---|---|
IPresentation | Returns the cloned presentation instance. |
Examples
//Create an instance for presentation
Presentation presentation = Presentation.Create() as Presentation;
//Add a new slide of comparison slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Comparison);
//Clone the entire presentation.
IPresentation presentationClone = presentation.Clone();
//Add a new slide of title layout type.
slide = presentationClone.Slides.Add(SlideLayoutType.Title);
//Add an auto shape of regular pentagon auto shape type.
slide.Shapes.AddShape(AutoShapeType.RegularPentagon, 10, 20, 300, 400);
//Save the cloned presentation
presentationClone.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
//Close the cloned presentation.
presentationClone.Close();
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add a new slide of comparison slide layout type.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Comparison)
'Clone the entire presentation.
Dim presentationClone As IPresentation = presentation__1.Clone()
'Add a new slide of title layout type.
slide = presentationClone.Slides.Add(SlideLayoutType.Title)
'Add an auto shape of regular pentagon auto shape type.
slide.Shapes.AddShape(AutoShapeType.RegularPentagon, 10, 20, 300, 400)
'Save the cloned presentation
presentationClone.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
'Close the cloned presentation.
presentationClone.Close()
Close()
Releases any resources associated with the presentation instance.
Declaration
public void Close()
Examples
//Create a new presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Add a new slide of comparison slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Comparison);
//Save the presentation.
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Create a new presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add a new slide of comparison slide layout type.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Comparison)
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
Create()
Creates a new IPresentation instance.
Declaration
public static IPresentation Create()
Returns
Type | Description |
---|---|
IPresentation | Returns the newly created presentation instance. |
Examples
//Create a new presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Add a new slide of comparison slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Comparison);
//Save the presentation.
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Create a new presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add a new slide of comparison slide layout type.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Comparison)
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
Dispose()
Releases all resources used by the Presentation instance.
Declaration
public void Dispose()
Examples
//Create a new presentation.
IPresentation presentation = Presentation.Create();
//Add a new slide of comparison slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Comparison);
//Save the presentation.
presentation.Save("Sample.pptx");
//Dispose the presentation.
presentation.Dispose();
'Create a new presentation.
Dim presentation__1 As IPresentation = Presentation.Create()
'Add a new slide of comparison slide layout type.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Comparison)
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Dispose the presentation.
presentation__1.Dispose()
Encrypt(String)
Encrypts the presentation using the specified password.
Declaration
public void Encrypt(string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | password | Password to encrypt the presentation. |
Examples
//Create a new presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Add a new slide of content with caption slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.ContentWithCaption);
//Add a auto shape of moon type auto shape.
IShape shape = slide.Shapes.AddShape(AutoShapeType.Moon, 50, 0, 200, 200);
//Add a paragraph with text content to the shape.
shape.TextBody.AddParagraph("Text for moon shape");
//Encrypt the presentation with the combination of alpha and symbol string password.
presentation.Encrypt("MYPASSWORD!@#$%");
//Save the presentation.
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Create a new presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add a new slide of content with caption slide layout type.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.ContentWithCaption)
'Add a auto shape of moon type auto shape.
Dim shape As IShape = slide.Shapes.AddShape(AutoShapeType.Moon, 50, 0, 200, 200)
'Add a paragraph with text content to the shape.
shape.TextBody.AddParagraph("Text for moon shape")
'Encrypt the presentation with the combination of alpha and symbol string password.
presentation__1.Encrypt("MYPASSWORD!@#$%")
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
Find(String, Boolean, Boolean)
Finds the first occurance of the given word from the presentation
Declaration
public ITextSelection Find(string textToFind, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | textToFind | |
System.Boolean | caseSensitive | |
System.Boolean | wholeWord |
Returns
Type | Description |
---|---|
ITextSelection | The ITextSelection that contains the found text in the document. |
Examples
//Create a new presentation instance.
IPresentation presentation = Presentation.Create();
//Add the slide into the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
// Add a text box to hold the list
IShape textBoxShape = slide.AddTextBox(65, 140, 410, 270);
// Add a new paragraph with a text
IParagraph paragraph = textBoxShape.TextBody.AddParagraph("Hello World");
// Finds the text from the Presentation document
ITextSelection textSelection = presentation.Find("World", false, false);
// Gets the found text containing text parts
foreach (ITextPart textPart in textSelection.GetTextParts())
{
//Sets Bold property
textPart.Font.Bold = true;
}
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Creates a presentation.
Dim presentation__1 As IPresentation = Presentation.Create()
'Add the slide into the presentation
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Blank)
'Add a text box to hold the list
Dim textBoxShape As IShape = slide.AddTextBox(65, 140, 410, 270)
'Add a new paragraph with a text
Dim paragraph As IParagraph = textBoxShape.TextBody.AddParagraph("Hello World")
'Finds the text from the Presentation document
Dim textSelection As ITextSelection = presentation__1.Find("World", False, False)
'Gets the text parts from the selection
For Each textPart As ITextPart In textSelection.GetTextParts()
textPart.Font.Bold = True
Next
presentation__1.Save("Output.pptx")
'Close the presentation.
presentation__1.Close()
Find(Regex)
Finds the first occurance of the given word from the presentation using Regex Pattern
Declaration
public ITextSelection Find(Regex pattern)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern |
Returns
Type | Description |
---|---|
ITextSelection | The ITextSelection that contains the found text in the document. |
Examples
//Opens an existing presentation.
IPresentation pptxDoc = Presentation.Open("Input.pptx");
// Create a regex pattern to find a text that starts with 'H' and ends with 'o'.
Regex regex = new Regex("H.+?o");
//Find the first occurrence of a specified regular expression.
ITextSelection textSelection = pptxDoc.Find(regex);
//Gets the found text as single text part
ITextPart textPart = textSelection.GetAsOneTextPart();
//Replace the text
textPart.Text = "Replaced text";
//Saves the Presentation
pptxDoc.Save("Output.pptx");
//Close the presentation
pptxDoc.Close();
'Opens an existing presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Input.pptx")
'Create a regex pattern to find a text that starts with 'H' and ends with 'o'.
Dim regex As Regex = New Regex("H.+?o")
'Find the first occurrence of a specified regular expression.
Dim textSelection As ITextSelection = pptxDoc.Find(regex)
'Gets the found text as single text part
Dim textPart As ITextPart = textSelection.GetAsOneTextPart()
'Replace the text
textPart.Text = "Replaced text"
'Saves the Presentation
pptxDoc.Save("Output.pptx")
'Close the presentation.
pptxDoc.Close()
FindAll(String, Boolean, Boolean)
Finds all the given text from the presentation document
Declaration
public ITextSelection[] FindAll(string textToFind, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | textToFind | |
System.Boolean | caseSensitive | |
System.Boolean | wholeWord |
Returns
Type | Description |
---|---|
ITextSelection[] | The ITextSelection collection that contains all the entries of the found text in the document. |
Examples
//Create a new presentation instance.
IPresentation presentation = Presentation.Create();
//Add the slide into the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
// Add a text box to hold the list
IShape textBoxShape = slide.AddTextBox(65, 140, 410, 270);
// Add a new paragraph with a text
IParagraph paragraph = textBoxShape.TextBody.AddParagraph("Hello World");
// Finds all the text from the Presentation document
ITextSelection[] textSelections = presentation.FindAll("World", false, false);
foreach (ITextSelection textSelection in textSelections)
{
//Gets the found text as single text part
ITextPart textPart = textSelection.GetAsOneTextPart();
//Replace the text
textPart.Text = "Replaced text";
}
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Creates a presentation.
Dim pptxDoc As IPresentation = Presentation.Create()
'Add the slide into the presentation
Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add a text box to hold the list
Dim textBoxShape As IShape = slide.AddTextBox(65, 140, 410, 270)
'Add a new paragraph with a text
Dim paragraph As IParagraph = textBoxShape.TextBody.AddParagraph("Hello World")
'Finds the text from the Presentation document
Dim textSelections As ITextSelection() = pptxDoc.FindAll("World", False, False)
'Gets the found text as single text part and replace it
For Each textSelection As ITextSelection In textSelections
Dim textPart As ITextPart = textSelection.GetAsOneTextPart()
textPart.Text = "Replaced text"
Next
pptxDoc.Save("Output.pptx")
'Close the presentation.
pptxDoc.Close()
FindAll(Regex)
Finds all the given text from the presentation document using Regex Pattern
Declaration
public ITextSelection[] FindAll(Regex pattern)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern |
Returns
Type | Description |
---|---|
ITextSelection[] | The ITextSelection collection that contains all the entries of the found text in the document. |
Examples
//Opens an existing presentation.
IPresentation pptxDoc = Presentation.Open("Input.pptx");
// Create a regex pattern to find a text that starts with 'H' and ends with 'o'.
Regex regex = new Regex("H.+?o");
//Finds all the occurrences of a specified regular expression.
ITextSelection[] textSelections = pptxDoc.FindAll(regex);
foreach (ITextSelection textSelection in textSelections)
{
//Gets the found text as single text part
ITextPart textPart = textSelection.GetAsOneTextPart();
//Replace the text
textPart.Text = "Replaced text";
}
//Saves the Presentation
pptxDoc.Save("Output.pptx");
// Close the presentation.
pptxDoc.Close();
'Opens an existing presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Input.pptx")
' Create a regex pattern to find a text that starts with 'H' and ends with 'o'.
Dim regex As Regex = New Regex("H.+?o")
'Finds all the occurrences of a specified regular expression.
Dim textSelections As ITextSelection() = pptxDoc.FindAll(regex)
For Each textSelection As ITextSelection In textSelections
'Gets the found text as single text part
Dim textPart As ITextPart = textSelection.GetAsOneTextPart()
'Replace the text
textPart.Text = "Replaced text"
Next
'Saves the Presentation
pptxDoc.Save("Output.pptx")
'Close the presentation.
pptxDoc.Close()
Open(Stream)
Opens the presentation from the specified stream.
Declaration
public static IPresentation Open(Stream fileStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | fileStream | The stream instance that represents the presentation. |
Returns
Type | Description |
---|---|
IPresentation | Returns a IPresentation object that represents the opened presentation. |
Remarks
From v20.4.0.x release, this method will not dispose the given System.IO.Stream. You should handle the disposal of System.IO.Stream in your application.
Examples
//Create instance for memory stream
MemoryStream fileStream = new MemoryStream();
//Open a presentation
IPresentation presentation = Presentation.Open(fileStream);
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
//Dispose the filestream
fileStream.Dispose();
'Create instance for memory stream
Dim fileStream As New MemoryStream()
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open(fileStream)
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
'Dispose the filestream
fileStream.Dispose()
Open(Stream, String)
Opens the encrypted presentation from the specified stream and password.
Declaration
public static IPresentation Open(Stream stream, string password)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The System.IO.Stream instance of the presentation. |
System.String | password | The password required to open the presentation. |
Returns
Type | Description |
---|---|
IPresentation | Returns the IPresentation object that represents the opened presentation. |
Remarks
From v20.4.0.x release, this method will not dispose the given System.IO.Stream. You should handle the disposal of System.IO.Stream in your application.
Examples
//Create instance for memory stream
MemoryStream fileStream = new MemoryStream();
//Open a presentation
string InputPath = "";
IPresentation presentation = Presentation.Open(fileStream,InputPath);
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
//Dispose the filestream
fileStream.Dispose();
'Create instance for memory stream
Dim fileStream As New MemoryStream()
'Open a presentation
Dim presentation__1 As IPresentation = Presentation.Open(fileStream, Input.pptx)
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
'Dispose the filestream
fileStream.Dispose()
Open(String)
Opens the presentation from the specified file name.
Declaration
public static IPresentation Open(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | Specifies the file name of the presentation to open. |
Returns
Type | Description |
---|---|
IPresentation | Returns a IPresentation object that represents the opened presentation. |
Examples
//Open a presentation.
Presentation presentation = Presentation.Open("Input.pptx") as Presentation;
//Add a new slide of comparison slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Comparison);
//Save the presentation.
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Open a presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Open("Input.pptx"), Presentation)
'Add a new slide of comparison slide layout type.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Comparison)
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Close the presentation
presentation__1.Close()
Open(String, String)
Opens the encrypted presentation from the specified file name and password.
Declaration
public static IPresentation Open(string fileName, string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | Path of the presentation file. |
System.String | password | Password required to open the presentation file. |
Returns
Type | Description |
---|---|
IPresentation | Returns a IPresentation object that represents the opened presentation. |
Examples
//Open the encrypted presentation.
Presentation presentation = Presentation.Open("Input.pptx", "MYPASSWORD!@#$%") as Presentation;
//Save the presentation.
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Open the encrypted presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Open("Input.pptx", "MYPASSWORD!@#$%"), Presentation)
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
RemoveEncryption()
Removes the encryption from presentation.
Declaration
public void RemoveEncryption()
Remarks
To remove the encryption we must have opened the presentation with password.
Examples
//Open the encrypted presentation.
Presentation presentation = Presentation.Open("Input.pptx", "MYPASSWORD!@#$%") as Presentation;
//Remove the encryption.
presentation.RemoveEncryption();
//Save the presentation.
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Open the encrypted presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Open("Input.pptx", "MYPASSWORD!@#$%"), Presentation)
'Remove the encryption.
presentation__1.RemoveEncryption()
'Save the presentation.
presentation__1.Save("Sample.pptx")
'Close the presentation.
presentation__1.Close()
RemoveMacros()
Removes the macros from the presentation instance.
Declaration
public void RemoveMacros()
Examples
//Opens an existing macro enabled PowerPoint presentation
IPresentation pptxDoc = Presentation.Open("Sample.PPTM");
//Checks whether the presentation has macros and then removes them
if (pptxDoc.HasMacros)
pptxDoc.RemoveMacros();
//Saves the presentation
pptxDoc.Save("Output.pptx");
//Closes the presentation
pptxDoc.Close();
'Opens an existing macro enabled PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Open("Sample.PPTM")
'Checks whether the presentation has macros and then removes them
If pptxDoc.HasMacros Then
pptxDoc.RemoveMacros()
End If
'Saves the presentation
pptxDoc.Save("Output.pptx")
'Closes the presentation
pptxDoc.Close()
RemoveWriteProtection()
Removes the write Protection from presentation instance
Declaration
public void RemoveWriteProtection()
Examples
//Create an instance for presentation
IPresentation presentation = Presentation.Open("Sample.pptx");
//Check whether the presentation is write protected.
if (presentation.IsWriteProtected)
{
//Removes the write protection from presentation instance
presentation.RemoveWriteProtection();
}
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation.
presentation.Close();
'Create an instance for presentation
Dim presentation As IPresentation = Presentation.Open("Sample.pptx")
'Check whether the presentation is write protected.
if (presentation.IsWriteProtected)
{
'Removes the write protection from presentation instance
presentation.RemoveWriteProtection()
}
'Save the presentation
presentation.Save("Output.pptx")
'Close the presentation.
presentation.Close()
RenderAsImages(ExportImageFormat)
Converts the slides in presentation to images using the specified image format.
Declaration
public Stream[] RenderAsImages(ExportImageFormat imageFormat)
Parameters
Type | Name | Description |
---|---|---|
ExportImageFormat | imageFormat | Specifies the image format in which you want to convert slides. |
Returns
Type | Description |
---|---|
System.IO.Stream[] | Returns the System.IO.Stream array of the converted images. |
Examples
//Create a new presentation.
Presentation presentation = Presentation.Create() as Presentation;
//Add a content with caption slide to the presentation.
ISlide slide = presentation.Slides.Add(SlideLayoutType.ContentWithCaption);
//Add a table to the slide.
ITable table = slide.Tables.AddTable(5, 5, 0, 0, 500, 500);
//Set the built in table style.
table.BuiltInStyle = BuiltInTableStyle.DarkStyle2Accent3Accent4;
//Iterate through the row collection.
foreach (IRow row in table.Rows)
{
//Iterate through the cell collection.
foreach (ICell cell in row.Cells)
{
//Add a paragraph to the cell.
cell.TextBody.AddParagraph("New Paragraph");
}
}
//Converts the each and every slide in the presentation to image of stream array type.
Stream[] imageStreamArray = presentation.RenderAsImages(ExportImageFormat.Jpeg);
//Iterate the stream array.
foreach (Stream stream in imageStreamArray)
{
//Save the stream in image of .jpg format.
Image.FromStream(stream).Save("RenderAsImage" + Guid.NewGuid() + ".jpg");
}
//Close the presentation.
presentation.Close();
'Create a new presentation.
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add a content with caption slide to the presentation.
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.ContentWithCaption)
'Add a table to the slide.
Dim table As ITable = slide.Tables.AddTable(5, 5, 0, 0, 500, 500)
'Set the built in table style.
table.BuiltInStyle = BuiltInTableStyle.DarkStyle2Accent3Accent4
'Iterate through the row collection.
For Each row As IRow In table.Rows
'Iterate through the cell collection.
For Each cell As ICell In row.Cells
'Add a paragraph to the cell.
cell.TextBody.AddParagraph("New Paragraph")
Next
Next
'Converts the each and every slide in the presentation to image of stream array type.
Dim imageStreamArray As Stream() = presentation__1.RenderAsImages(ExportImageFormat.Jpeg)
'Iterate the stream array.
For Each stream As Stream In imageStreamArray
'Save the stream in image of .jpg format.
Image.FromStream(stream).Save("RenderAsImage" + Guid.NewGuid() + ".jpg")
Next
'Close the presentation.
presentation__1.Close()
Save(Stream)
Declaration
public void Save(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream |
Remarks
At present, the Essential Presentation library only supports the PPTX file format.
Examples
//Create instance for memory stream
MemoryStream fileStream = new MemoryStream();
//Create an instance of presentation
Presentation presentation = Presentation.Create() as Presentation;
//Save the presentation using stream
presentation.Save(fileStream);
//Close the presentation.
presentation.Close();
//Dispose the filestream
fileStream.Dispose();
'Create instance for memory stream
Dim fileStream As New MemoryStream()
'Create an instance of presentation
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Save the presentation using stream
presentation__1.Save(fileStream)
'Close the presentation.
presentation__1.Close()
'Dispose the filestream
fileStream.Dispose()
Save(String)
Saves the presentation to the specified file name.
Declaration
public void Save(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | Specifies the file name to save the presentation. |
Remarks
At present, the Essential Presentation library only supports the PPTX file format.
Examples
//Create an instance of presentation
Presentation presentation = Presentation.Create() as Presentation;
//Add slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
//Add table to the slide
ITable table = slide.Shapes.AddTable(3, 3, 100, 120, 300, 200);
//Save the presentation
presentation.Save("Output.pptx");
//Close the presentation
presentation.Close();
'Create an instance of presentation
Dim presentation__1 As Presentation = TryCast(Presentation.Create(), Presentation)
'Add slide to the presentation
Dim slide As ISlide = presentation__1.Slides.Add(SlideLayoutType.Blank)
'Add table to the slide
Dim table As ITable = slide.Shapes.AddTable(3, 3, 100, 120, 300, 200)
'Save the presentation
presentation__1.Save("Output.pptx")
'Close the presentation
presentation__1.Close()
SetWriteProtection(String)
Sets the write protection for the presentation instance
Declaration
public void SetWriteProtection(string password)
Parameters
Type | Name | Description |
---|---|---|
System.String | password | Password to enforce protection. |
Remarks
Maximum length of password should be 15. If it exceeds 15, first 15 characters will be considered for protection, remaining will be ignored.
Examples
//Create an instance for presentation
IPresentation presentation = Presentation.Create();
//Add a new slide of comparison slide layout type.
ISlide slide = presentation.Slides.Add(SlideLayoutType.Comparison);
//Add an auto shape of regular pentagon auto shape type.
slide.Shapes.AddShape(AutoShapeType.RegularPentagon, 10, 20, 300, 400);
//Set the write protection for Presentation instance with password.
presentation.SetWriteProtection("MYPASSWORD");
//Save the presentation
presentation.Save("Sample.pptx");
//Close the presentation.
presentation.Close();
'Create an instance for presentation
Dim presentation As IPresentation = Presentation.Create()
'Add a new slide of comparison slide layout type.
Dim slide As ISlide = presentation.Slides.Add(SlideLayoutType.Comparison)
'Add an auto shape of regular pentagon auto shape type.
slide.Shapes.AddShape(AutoShapeType.RegularPentagon, 10, 20, 300, 400)
'Set the write protection for Presentation instance with password.
presentation.SetWriteProtection("MYPASSWORD")
'Save the presentation
presentation.Save("Sample.pptx")
'Close the presentation.
presentation.Close()