By default, anyone who can access a PowerPoint document can open and edit it. If you want to prevent your PowerPoint document from unauthorized viewing or modification, you can protect it with a password. In addition to adding password protection, you can also choose other ways to protect the document, such as marking it as final to discourage editing. When you want to make the document public, you can unprotect it at any time. In this article, we will demonstrate how to protect or unprotect PowerPoint documents in C# and VB.NET using Spire.Presentation for .NET.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Protect a PowerPoint Document with a Password in C# and VB.NET

You can protect a PowerPoint document with a password to ensure that only the people who have the right password can view and edit it.

The following steps demonstrate how to protect a PowerPoint document with a password:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Encrypt the document with a password using Presentation.Encrypt() method.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace ProtectPPTWithPassword
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation presentation = new Presentation();

            //Load a PowerPoint document
            presentation.LoadFromFile(@"Sample.pptx");

            //Encrypt the document with a password
            presentation.Encrypt("your password");

            //Save the result document
            presentation.SaveToFile("Encrypted.pptx", FileFormat.Pptx2013);
        }
    }
}

C#/VB.NET: Protect or Unprotect PowerPoint Documents

Mark a PowerPoint Document as Final in C# and VB.NET

You can mark a PowerPoint document as final to inform readers that the document is final and no further editing is expected.

The following steps demonstrate how to mark a PowerPoint document as final:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Mark the document as final through Presentation.DocumentProperty[] property.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace MarkPPTAsFinal
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load a PowerPoint document
            ppt.LoadFromFile(@"Sample.pptx");

            //Mark the document as final
            ppt.DocumentProperty["_MarkAsFinal"] = true;

            //Save the result document
            ppt.SaveToFile("MarkAsFinal.pptx", FileFormat.Pptx2013);
        }
    }
}

C#/VB.NET: Protect or Unprotect PowerPoint Documents

Remove Password Protection from a PowerPoint Document in C# and VB.NET

You can remove password protection from a PowerPoint document by loading the document with the correct password, then removing the password protection from it.

The following steps demonstrate how to remove password protection from a PowerPoint document:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Mark the document as final through Presentation.RemoveEncryption() method.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace RemovePasswordProtectionFromPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation presentation = new Presentation();

            //Load a password-protected PowerPoint document with the right password
            presentation.LoadFromFile(@"Encrypted.pptx", "your password");

            //Remove password protection from the document
            presentation.RemoveEncryption();

            //Save the result document
            presentation.SaveToFile("RemoveProtection.pptx", FileFormat.Pptx2013);
        }
    }
}

C#/VB.NET: Protect or Unprotect PowerPoint Documents

Remove Mark as Final Option from a PowerPoint Document in C# and VB.NET

The mark as final feature makes a PowerPoint document read-only to prevent further changes, if you decide to make changes to the document later, you can remove the mark as final option from it.

The following steps demonstrate how to remove mark as final option from a PowerPoint document:

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Mark the document as final through Presentation.DocumentProperty[] property.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace RemoveMarkAsFinalFromPPT
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load a PowerPoint document
            ppt.LoadFromFile(@"MarkAsFinal.pptx");

            //Remove mark as final option from the document
            ppt.DocumentProperty["_MarkAsFinal"] = false;

            //Save the result document
            ppt.SaveToFile("RemoveMarkAsFinal.pptx", FileFormat.Pptx2013);
        }
    }
}

C#/VB.NET: Protect or Unprotect PowerPoint Documents

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Print a PowerPoint document

2014-05-09 01:04:13 Written by Koohji

Spire.Presentation for .NET, a reliable .NET PPT component, enables you to generate, read, edit, convert even print your PPT documents without installing Microsoft PowerPoint on your machine. Using Spire.Presentation for .NET, you can use the presentation.Print() method to print your PPT documents in a fast speed.The following article will introduce a detail method to print a PPT document with C#, VB via Spire.Presentation for .NET.

Download and install Spire.Presentation for .NET and use below code to experience this method to print PPT document.

The main steps of method are:

Step 1: Create a PPT document.

Presentation presentation = new Presentation();

Step 2: Append new shape and paragraph to add the text.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250));
shape.TextFrame.Paragraphs.Append(new TextParagraph());

Step 3: Set the background to DarkSeaGreen.

presentation.Slides[0].SlideBackground.Type = BackgroundType.Custom;
presentation.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid;
presentation.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen;

Step 4: Create a printerSettings and print the PPT.

PrinterSettings printerSettings = new PrinterSettings();
presentation.Print(printerSettings);

Suppose you've succeeded use the method, the printer icon would appear in the lower right corner ofscreen. such as: Print a PPT document

If you couldn't successfully use the Spire.presentation, please refer the Spire.Presentation Quick Start which can guide you quickly use the Spire.presentation.

The full code:

[C#]
using System.Drawing;
using System.Drawing.Printing;
using Spire.Presentation;
using Spire.Presentation.Drawing;

namespace PrintPPT
{
    class Program
    {
        static void Main(string[] args)
        {            
            //create PPT document
            Presentation presentation = new Presentation();

            //append new shape
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250));
            shape.ShapeStyle.LineColor.Color = Color.DarkSeaGreen;
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("The sample demonstrates how to Print PPT file.");

            //add new paragraph
            shape.TextFrame.Paragraphs.Append(new TextParagraph());

            //add text to paragraph            
            shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange("As an independent Office .NET component, Spire.Office doesn't need Microsoft Office to be installed on System. In addition, it is a better alternative to MS Office Automation in terms of security, stability, scalability, speed, price and features."));

            //set the Font
            foreach (TextParagraph para in shape.TextFrame.Paragraphs)
            {
                para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
                para.TextRanges[0].Fill.FillType = FillFormatType.Solid;
                para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                para.Alignment = TextAlignmentType.Left;
                para.Indent = 35;
            }

            //set the background to DarkSeaGreen            
            presentation.Slides[0].SlideBackground.Type = BackgroundType.Custom;
            presentation.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid;
            presentation.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen;

            //print
            PrinterSettings printerSettings = new PrinterSettings();
            presentation.Print(printerSettings);            
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports System.Drawing.Printing
Imports Spire.Presentation
Imports Spire.Presentation.Drawing

Namespace PrintPPT
	Class Program
		Private Shared Sub Main(args As String())
			'create PPT document
			Dim presentation As New Presentation()

			'append new shape
			Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 150, 600, 250))
			shape.ShapeStyle.LineColor.Color = Color.DarkSeaGreen
			shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None

			'add text to shape
			shape.AppendTextFrame("The sample demonstrates how to Print PPT file.")

			'add new paragraph
			shape.TextFrame.Paragraphs.Append(New TextParagraph())

			'add text to paragraph            
			shape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange("As an independent Office .NET component, Spire.Office doesn't need Microsoft Office to be installed on System. In addition, it is a better alternative to MS Office Automation in terms of security, stability, scalability, speed, price and features."))

			'set the Font
			For Each para As TextParagraph In shape.TextFrame.Paragraphs
				para.TextRanges(0).LatinFont = New TextFont("Arial Rounded MT Bold")
				para.TextRanges(0).Fill.FillType = FillFormatType.Solid
				para.TextRanges(0).Fill.SolidColor.Color = Color.Black
				para.Alignment = TextAlignmentType.Left
				para.Indent = 35
			Next

			'set the background to DarkSeaGreen            
			presentation.Slides(0).SlideBackground.Type = BackgroundType.[Custom]
			presentation.Slides(0).SlideBackground.Fill.FillType = FillFormatType.Solid
			presentation.Slides(0).SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen

			'print
			Dim printerSettings As New PrinterSettings()
			presentation.Print(printerSettings)
		End Sub
	End Class
End Namespace

Spire.Presentation, a professional .NET component especially designed for developers enables you to manipulate PPT files easily and flexibly. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. You can also set the properties of PPT document using Spire.Presentation. And it is a quiet an easy work. Here I will show you how to do so.

Step 1: Create a PPT document.

Presentation presentation = new Presentation();

Step 2: Add some context to PPT document such as image and text.

Step 3: Set the properties of the PPT document.

presentation.DocumentProperty.Application = "Spire.Presentation";
presentation.DocumentProperty.Author = "http://www.e-iceblue.com/";
presentation.DocumentProperty.Company = "E-iceblue";
presentation.DocumentProperty.Keywords = "Demo File";
presentation.DocumentProperty.Comments = "This file tests Spire.Presentation.";
presentation.DocumentProperty.Category = "Demo";
presentation.DocumentProperty.Title = "This is a demo file.";
presentation.DocumentProperty.Subject = "Test";

Step 4: Save the PPT document.

presentation.SaveToFile("para.pptx", FileFormat.Pptx2010);

Screenshot:

Set the properties of the PPT document

Full code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace SetProperties
{
    class Program
    {
        static void Main(string[] args)
        {

            //create PPT document
            Presentation presentation = new Presentation();

            //set background Image
            string ImageFile = "bg.png";
            RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //set the DocumentProperty of PPT document
            presentation.DocumentProperty.Application = "Spire.Presentation";
            presentation.DocumentProperty.Author = "http://www.e-iceblue.com/";
            presentation.DocumentProperty.Company = "E-iceblue";
            presentation.DocumentProperty.Keywords = "Demo File";
            presentation.DocumentProperty.Comments = "This file tests Spire.Presentation.";
            presentation.DocumentProperty.Category = "Demo";
            presentation.DocumentProperty.Title = "This is a demo file.";
            presentation.DocumentProperty.Subject = "Test";

            //append new shape
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 250));
            shape.ShapeStyle.LineColor.Color = Color.White;
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;

            //add text to shape
            shape.AppendTextFrame("The sample demonstrates how to Set DocumentProperty of PPT using Spire.Presentation.");

            //add new paragraph
            shape.TextFrame.Paragraphs.Append(new TextParagraph());

            //add text to paragraph
            shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange("Spire.Office for .NET is a compilation of Enterprise-Level Office .NET component offered by E-iceblue. It includes Spire.Doc, Spire XLS, Spire.PDF, Spire.DataExport, Spire.PDFViewer, Spire.DocViewer, and Spire.BarCode. Spire.Office contains the most up-to-date versions of the above .NET components."));

            //set the Font
            foreach (TextParagraph para in shape.TextFrame.Paragraphs)
            {
                para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
                para.TextRanges[0].Fill.FillType = FillFormatType.Solid;
                para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
                para.Alignment = TextAlignmentType.Left;
                para.Indent = 35;
            }

            //save the document
            presentation.SaveToFile("DocumentProperty.pptx", FileFormat.Pptx2007);
            System.Diagnostics.Process.Start("DocumentProperty.pptx");

        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace SetProperties
	Class Program
		Private Shared Sub Main(args As String())

			'create PPT document
			Dim presentation As New Presentation()

			'set background Image
			Dim ImageFile As String = "bg.png"
			Dim rect As New RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height)
			presentation.Slides(0).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect)
			presentation.Slides(0).Shapes(0).Line.FillFormat.SolidFillColor.Color = Color.FloralWhite

			'set the DocumentProperty of PPT document
			presentation.DocumentProperty.Application = "Spire.Presentation"
			presentation.DocumentProperty.Author = "http://www.e-iceblue.com/"
			presentation.DocumentProperty.Company = "E-iceblue"
			presentation.DocumentProperty.Keywords = "Demo File"
			presentation.DocumentProperty.Comments = "This file tests Spire.Presentation."
			presentation.DocumentProperty.Category = "Demo"
			presentation.DocumentProperty.Title = "This is a demo file."
			presentation.DocumentProperty.Subject = "Test"

			'append new shape
			Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 600, 250))
			shape.ShapeStyle.LineColor.Color = Color.White
			shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None

			'add text to shape
			shape.AppendTextFrame("The sample demonstrates how to Set DocumentProperty of PPT using Spire.Presentation.")

			'add new paragraph
			shape.TextFrame.Paragraphs.Append(New TextParagraph())

			'add text to paragraph
			shape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange("Spire.Office for .NET is a compilation of Enterprise-Level Office .NET component offered by E-iceblue. It includes Spire.Doc, Spire XLS, Spire.PDF, Spire.DataExport, Spire.PDFViewer, Spire.DocViewer, and Spire.BarCode. Spire.Office contains the most up-to-date versions of the above .NET components."))

			'set the Font
			For Each para As TextParagraph In shape.TextFrame.Paragraphs
				para.TextRanges(0).LatinFont = New TextFont("Arial Rounded MT Bold")
				para.TextRanges(0).Fill.FillType = FillFormatType.Solid
				para.TextRanges(0).Fill.SolidColor.Color = Color.Black
				para.Alignment = TextAlignmentType.Left
				para.Indent = 35
			Next

			'save the document
			presentation.SaveToFile("DocumentProperty.pptx", FileFormat.Pptx2007)
			System.Diagnostics.Process.Start("DocumentProperty.pptx")

		End Sub
	End Class
End Namespace
page 268