Generally, we tend to insert graphics, animation effects, audio frames or video frames into our PPT slides to make it more vivid and persuasive. Adding high-quality audio, background music for example, to a slide presentation can greatly increase the impact that it has on your viewers.
Spire.Presentation for .NET is a comprehensive toolkit which allows developers to process PPT slides in massive ways, including multitude of graphics and multimedia features. In this topic, we will make a simple introduction of how to insert audio into PPT using C#.
Step 1: Create a new PPT document first
Presentation presentation = new Presentation()
Step 2: Basically, we need to set a background image before inserting Audio file
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;
Step 3: Load the Audio file from disk
presentation.Slides[0].Shapes.AppendAudioMedia(Path.GetFullPath("paipai_sound.wav"), new RectangleF(100, 100, 20, 20));
Step 4: Set properties of AutoShape
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250)); shape.ShapeStyle.LineColor.Color = Color.White; shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
Step 5: Save PPT file
presentation.SaveToFile("Audio.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("Audio.pptx");
Effect Screenshot:
With Spire.Presentation, you can insert audio into your PowerPoint documents and do more same thing in your any .NET(C#, VB.NET, ASP.NET) applications without PowerPoint automation and any other third party add-ins.