How C # Adds a PPT background (solid background, gradient background, picture background)

Source: Internet
Author: User

Overview

When we create a PowerPoint document, the system's default slide is a blank background, and many times we need to customize the slide background to achieve beautiful document effects. The following example shows a way to set the background for a PowerPoint slide, consisting mainly of the following three sections:

    • Add a solid color background
    • Add a gradient background
    • Add a picture as a tool for the background
    • Free spire.presentation for. NET version 3.3 (Community edition)
Sample code (for reference)

Step 1: Add the following using directives

using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;

Step 2: Create a document

Presentation ppt = new Presentation();ppt.LoadFromFile("test.pptx");

Step 3: Add a solid color background

//设置文档的背景填充模式为纯色填充ppt.Slides[0].SlideBackground.Type = BackgroundType.Custom;ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid;ppt.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.Pink;

Step 4: Add a gradient background color

//设置文档的背景填充模式为渐变色填充ppt.Slides[1].SlideBackground.Type = BackgroundType.Custom;ppt.Slides[1].SlideBackground.Fill.FillType = FillFormatType.Gradient;ppt.Slides[1].SlideBackground.Fill.Gradient.GradientStops.Append(0f, KnownColors.Yellow);ppt.Slides[1].SlideBackground.Fill.Gradient.GradientStops.Append(1f, KnownColors.Orange);

Step 5: Add a picture as a background

//设置幻灯片背景色为图片背景ppt.Slides[2].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;ppt.Slides[2].SlideBackground.Fill.FillType = FillFormatType.Picture;ppt.Slides[2].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;//加载图片作为幻灯片背景Image img = Image.FromFile("green.png");IImageData image = ppt.Images.Append(img);ppt.Slides[2].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

Step 6: Save the file

ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);System.Diagnostics.Process.Start("result.pptx");

After the code is finished, debug the Run program and generate the file as follows:

All code:

Using spire.presentation;using spire.presentation.drawing;using System.drawing;namespace AddBackground_PPT{class program {static void Main (string[] args) {//Instantiate presentation class, load PowerPoint document Prese            ntation ppt = new Presentation (); Ppt.            LoadFromFile ("Test.pptx"); Sets the background fill mode for the document to fill the PPT with a solid color. Slides[0].            Slidebackground.type = Backgroundtype.custom; Ppt. Slides[0].            SlideBackground.Fill.FillType = Fillformattype.solid; Ppt. Slides[0].            SlideBackground.Fill.SolidColor.Color = Color.pink; Sets the background fill mode for the document to fill the PPT with the gradient. SLIDES[1].            Slidebackground.type = Backgroundtype.custom; Ppt. SLIDES[1].            SlideBackground.Fill.FillType = fillformattype.gradient; Ppt. SLIDES[1].            SlideBackground.Fill.Gradient.GradientStops.Append (0f, Knowncolors.yellow); Ppt. SLIDES[1].            SlideBackground.Fill.Gradient.GradientStops.Append (1f, Knowncolors.orange); Sets the slide background color for the picture background ppt.SLIDES[2].            Slidebackground.type = Spire.Presentation.Drawing.BackgroundType.Custom; Ppt. SLIDES[2].            SlideBackground.Fill.FillType = fillformattype.picture; Ppt. SLIDES[2].            SlideBackground.Fill.PictureFill.FillType = Picturefilltype.stretch;            Load picture as slide background image img = image.fromfile ("Green.png"); Iimagedata image = ppt.            Images.append (IMG); Ppt. SLIDES[2].            SlideBackground.Fill.PictureFill.Picture.EmbedImage = image; Save and open the document PPT.            SaveToFile ("Result.pptx", fileformat.pptx2010);        System.Diagnostics.Process.Start ("Result.pptx"); }    }}

The end of this article.
If you want to reprint, please specify the source!!

How C # Adds a PPT background (solid background, gradient background, picture background)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.