Spire.Cloud.PowerPoint provides the SlidesApi interface to handle a specific slide inside a PowerPoint presentation. This article shows you how to add background color or image to a slide by using this API.
Example 1. Set background color
using Spire.Cloud.Powerpoint.Sdk.Client;
using Spire.Cloud.Powerpoint.Sdk.Api;
namespace SetBackgroundColor
{
class Program
{
static string appId = "App ID";
static string appKey = "App Key";
static string baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a SlidesApi object
static SlidesApi slidesApi = new SlidesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.pptx";
//Specify the slide index
int? slideIndex = 0;
//Specify the color
string color = "#BCD2EE";
//Specify the original password, set to null if there is no password
string password = null;
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
//Call SetSlideBackgroundColor to set background color for the specified slide
slidesApi.SetSlideBackgroundColor(name, slideIndex, color, folder, password, storage);
}
}
}
Example 2. Set background image
using Spire.Cloud.Powerpoint.Sdk.Client;
using Spire.Cloud.Powerpoint.Sdk.Api;
using Spire.Cloud.Powerpoint.Sdk.Model;
namespace SetBackgroundImage
{
class Program
{
static string appId = "App ID";
static string appKey = "App Key";
static string baseUrl = "https://api.cloudxdocs.com";
//Create a Configuration object based on App ID, App Key and base URL
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a SlidesApi object
static SlidesApi slidesApi = new SlidesApi(configuration);
static void Main(string[] args)
{
//Specify the source document name
string name = "sample.pptx";
//Specify the slide index
int? slideIndex = 0;
//Load an image from URL
string fileName = "input/image.jpg";
ResourceUriElement image = new ResourceUriElement(new ResourceUri(fileName));
//Create a SlideBackground object
SlideBackground background = new SlideBackground("custom");
//Fill the background with image
background.FillFormat = new PictureFill(0, 0, 0, 0, 96, image, null, null, "Stretch");
//Specify the original password, set to null if there is no password
string password = null;
//Specify the folder where the source document is stored
string folder = "input";
//Use the default storage, set to null
string storage = null;
var response = slidesApi.SetSlideBackground(name, slideIndex, background, folder, password, storage);
}
}
}