Security in Presentation

6 Dec 202410 minutes to read

To quickly start protecting PowerPoint presentations, please check out this video:

Encrypting with password

You can protect a PowerPoint Presentation by encrypting the document by using a password. This prevents unauthorized users to access or make changes in the Presentation.

The following code example demonstrates how to encrypt a PowerPoint Presentation with password.

//Open an existing presentation.
using (FileStream inputStream = new FileStream("Template.pptx", FileMode.Open, FileAccess.Read))
{
    using (IPresentation presentation = Presentation.Open(inputStream))
	{
		//Encrypt the presentation with a password.
		presentation.Encrypt("syncfusion");
		//Saves the Presentation.
		using (FileStream outputStream = new FileStream("Sample.pptx", FileMode.Create))
		{
			presentation.Save(outputStream);
		}
	}
}
//Open an existing presentation.
using (IPresentation presentation = Presentation.Open("Template.pptx"))
{
    //Encrypt the presentation with a password.
    presentation.Encrypt("syncfusion");
    //Saves the Presentation.
    presentation.Save("Sample.pptx");
}
'Open an existing presentation.
Using presentationDocument As IPresentation = Presentation.Open("Template.pptx")
    'Encrypt the presentation with a password.
    presentation.Encrypt("syncfusion")
    'Saves the Presentation.
    presentationDocument.Save("Sample.pptx")
End Using

You can download a complete working sample from GitHub.

Decrypting the PowerPoint Presentation

Essential® Presentation provides ability to remove the encryption from the PowerPoint Presentation. You can decrypt a PowerPoint Presentation by opening it with the password.

Opening the Encrypted PowerPoint Presentation

The following code example demonstrates opening the encrypted PowerPoint Presentation.

//Opens an existing Presentation from file system and it can be decrypted by using the provided password.
using (FileStream inputStream = new FileStream("Sample.pptx", FileMode.Open))
{
    using (IPresentation presentation = Presentation.Open(inputStream, "PASSWORD!@1#$"))
    {
        //Save the PowerPoint Presentation as stream.
        using (FileStream outputStream = new FileStream("Output.pptx", FileMode.Create))
        {
            presentation.Save(outputStream);
        }
    }
}
//Opens an existing Presentation from file system and it can be decrypted by using the provided password.
using (IPresentation presentation = Presentation.Open("Sample.pptx", "PASSWORD!@1#$"))
{
    //Saves the Presentation.
    presentation.Save("Output.pptx");
}
'Opens an existing Presentation from file system and it can be decrypted by using the provided password.
Using presentationDocument As IPresentation = Presentation.Open("Sample.pptx", "PASSWORD!@1#$")
    'Saves the Presentation
    presentationDocument.Save("Output.pptx")
End Using

Removing the encryption from Presentation

The following code example demonstrates removing the encryption from a PowerPoint Presentation.

//Opens an existing Presentation from file system and it can be decrypted by using the provided password.
using (FileStream inputStream = new FileStream("Sample.pptx", FileMode.Open))
{
    //Opens an existing Presentation from file system and it can be decrypted by using the provided password.
    using (IPresentation presentation = Presentation.Open(inputStream, "syncfusion"))
    {
        //Decrypts the document.
        presentation.RemoveEncryption();
        //Save the PowerPoint Presentation as stream.
        using (FileStream outputStream = new FileStream("Output.pptx", FileMode.Create))
        {
            presentation.Save(outputStream);
        }
    }
}
//Opens an existing Presentation from file system and it can be decrypted by using the provided password.
using (IPresentation presentation = Presentation.Open("Sample.pptx", "syncfusion"))
{
    //Decrypts the document.
    presentation.RemoveEncryption();
    //Saves the presentation.
    presentation.Save("Output.pptx");
}
'Opens an existing Presentation from file system and it can be decrypted by using the provided password.
Using presentationDocument As IPresentation = Presentation.Open("Sample.pptx", "syncfusion")
    'Decrypts the document.
    presentationDocument.RemoveEncryption()
    'Saves the Presentation.
    presentationDocument.Save("Output.pptx")
End Using

You can download a complete working sample from GitHub.

Write Protection

You can set write protection for a PowerPoint Presentation and remove protection from the write protected PowerPoint presentation.

Protect PowerPoint Presentation

You can protect a PowerPoint Presentation with password to restrict unauthorized editing.

The following code example shows how to set write protection for a PowerPoint Presentation.

//Create a new instance for PowerPoint presentation
IPresentation pptxDoc = Presentation.Create();
//Add the blank slide to the presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add the shape to the slide
IShape shape = slide.Shapes.AddShape(AutoShapeType.BlockArc, 0, 0, 200, 200);
//Add the paragraph to the shape.
IParagraph paragraph = shape.TextBody.AddParagraph("welcome");
//Sets the author name
pptxDoc.BuiltInDocumentProperties.Author = "Syncfusion";
//Set the write protection for presentation instance
pptxDoc.SetWriteProtection("MYPASSWORD");
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("Output.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Closes the presentation
pptxDoc.Close();
//Create a new instance for PowerPoint presentation
IPresentation pptxDoc = Presentation.Create();
//Add the blank slide to the presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Add the shape to the slide
IShape shape = slide.Shapes.AddShape(AutoShapeType.BlockArc, 0, 0, 200, 200);
//Add the paragraph to the shape.
IParagraph paragraph = shape.TextBody.AddParagraph("welcome");
//Sets the author name
pptxDoc.BuiltInDocumentProperties.Author = "Syncfusion";
//Set the write protection for presentation instance
pptxDoc.SetWriteProtection("MYPASSWORD");
//Saves the modified cloned PowerPoint presentation
pptxDoc.Save("Sample.pptx");
//Close the presentation instance
pptxDoc.Close();
'Create a new instance for PowerPoint presentation
IPresentation pptxDoc = Presentation.Create()
'Add the blank slide to the presentation
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
'Add the shape to the slide
IShape shape = slide.Shapes.AddShape(AutoShapeType.BlockArc, 0, 0, 200, 200)
'Add the paragraph to the shape.
IParagraph paragraph = shape.TextBody.AddParagraph("welcome")
'Sets the author name
pptxDoc.BuiltInDocumentProperties.Author = "Syncfusion"
'Set the write protection for presentation instance
pptxDoc.SetWriteProtection("MYPASSWORD")
'Saves the modified cloned PowerPoint presentation
pptxDoc.Save("Sample.pptx")
'Close the presentation instance
pptxDoc.Close()

You can download a complete working sample from GitHub.

Remove Protection

You can check whether a PowerPoint Presentation is write protected and remove protection from the write protected PowerPoint Presentation.

The following code example shows how to remove restriction protection from the write protected PowerPoint Presentation

//Loads or open an PowerPoint Presentation
FileStream inputStream = new FileStream("Sample.pptx",FileMode.Open);
IPresentation pptxDoc = Presentation.Open(inputStream);
//Gets whether the presentation is write Protected. Read - only.
bool writeProtected = pptxDoc.IsWriteProtected;
//Checks whether the presentation is write protected
if (writeProtected)
{
     //Removes the write protection for presentation instance.
     pptxDoc.RemoveWriteProtection();
}
//Save the PowerPoint Presentation as stream
FileStream outputStream = new FileStream("Output.pptx", FileMode.Create);
pptxDoc.Save(outputStream);
//Closes the presentation
pptxDoc.Close();
//Open the PowerPoint presentation
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Gets whether the presentation is write Protected. Read - only.
bool writeProtected = pptxDoc.IsWriteProtected;
//Checks whether the presentation is write protected
if (writeProtected)
{
     //Removes the write protection for presentation instance.
     pptxDoc.RemoveWriteProtection();
}
//Saves the modified cloned PowerPoint presentation
pptxDoc.Save("Output.pptx");
//Close the presentation instance
pptxDoc.Close();
'Open the PowerPoint presentation
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
'Gets whether the presentation is write Protected. Read - only.
bool writeProtected = pptxDoc.IsWriteProtected;
'Checks whether the presentation is write protected
if (writeProtected)
{
     'Removes the write protection for presentation instance.
     pptxDoc.RemoveWriteProtection();
}
'Saves the modified cloned PowerPoint presentation
pptxDoc.Save("Output.pptx")
'Close the presentation instance
pptxDoc.Close()

You can download a complete working sample from GitHub.

NOTE

  1. In Xamarin applications, Encryption, Decryption and Write Protection features are supported from the target framework .NET Standard 2.0 version onwards.
  2. For ASP.NET Core, Encryption, Decryption and Write Protection features are supported from the .NET Core 2.0 version onwards.

Online Demo

  • Explore how to set write protection for a PowerPoint presentation with a password using the .NET PowerPoint Library (Presentation) in a live demo here.
  • See how to encrypt and decrypt the PowerPoint presentation using the .NET PowerPoint Library (Presentation) in a live demo here.