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:
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