.NET (1316)
Children categories
We have demonstrated how to use Spire.Presentation to add text watermark and image watermark to the presentation slides. This article will show how to remove text and image watermarks in presentation slides in C#.
Firstly, view the sample document contains the text and image watermark.

Step 1: Create a presentation document and load the document from the file
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);
Step 2: Remove the text and image watermark.
Remove text watermark by removing the shape with contains the text string "Confidential".
for (int i = 0; i < ppt.Slides.Count; i++)
{
for (int j = 0; j < ppt.Slides[i].Shapes.Count; j++)
{
if (ppt.Slides[i].Shapes[j] is IAutoShape)
{
IAutoShape shape = ppt.Slides[i].Shapes[j] as IAutoShape;
if (shape.TextFrame.Text.Contains("Confidential"))
{
ppt.Slides[i].Shapes.Remove(shape);
}
}
}
}
Remove image watermark by setting SlideBackground.Fill.FillType as none.
for (int i = 0; i < ppt.Slides.Count; i++)
{
ppt.Slides[i].SlideBackground.Fill.FillType = FillFormatType.None;
}
Step 3: Save the document to file.
ppt.SaveToFile("RemoveWartermark.pptx", FileFormat.Pptx2013);
Effective screenshot after removing the text and image watermark:


Full codes:
Remove text watermark in presentation slides:
using Spire.Presentation;
namespace RemoveWatermark
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);
for (int i = 0; i < ppt.Slides.Count; i++)
{
for (int j = 0; j < ppt.Slides[i].Shapes.Count; j++)
{
if (ppt.Slides[i].Shapes[j] is IAutoShape)
{
IAutoShape shape = ppt.Slides[i].Shapes[j] as IAutoShape;
if (shape.TextFrame.Text.Contains("Confidential"))
{
ppt.Slides[i].Shapes.Remove(shape);
}
}
}
}
ppt.SaveToFile("RemoveTextWartermark.pptx", FileFormat.Pptx2013);
}
}
Remove image watermark in presentation slides:
using Spire.Presentation;
using Spire.Presentation.Drawing;
namespace RemoveWatermark
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample2.pptx", FileFormat.Pptx2013);
for (int i = 0; i < ppt.Slides.Count; i++)
{
ppt.Slides[i].SlideBackground.Fill.FillType = FillFormatType.None;
}
ppt.SaveToFile("RemovePicWatermak.pptx", FileFormat.Pptx2013);
}
}
}
By default, the data source of PivotTable won't be refreshed automatically. If we update the data source of our PivotTable, the PivotTable that was built on that data source needs to be refreshed. This article is going to elaborate how to refresh PivotTable in Excel programmatically in c# using Spire.XLS.
Below is the screenshot of the example Excel file:

Detail steps:
Step 1: Instantiate a Workbook object and load the Excel file.
Workbook workbook = new Workbook(); workbook.LoadFromFile(@"Sample.xlsx");
Step 2: Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
Step 3: update the data source of PivotTable.
sheet.Range["C2"].Value = "199";
Step 4: Get the PivotTable that was built on the data source.
XlsPivotTable pt = workbook.Worksheets[0].PivotTables[0] as XlsPivotTable;
Step 5: Refresh the data of PivotTable.
pt.Cache.IsRefreshOnLoad = true;
Step 6: Save the file.
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);
Output after updating data source and refreshing the PivotTable:

Full code:
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.PivotTables;
namespace Refresh_Pivot_Table_in_Excel
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Workbook object
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile(@"Sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//Update the data source of PivotTable
sheet.Range["C2"].Value = "199";
//Get the PivotTable that was built on the data source
XlsPivotTable pt = workbook.Worksheets[0].PivotTables[0] as XlsPivotTable;
//Refresh the data of PivotTable
pt.Cache.IsRefreshOnLoad = true;
//Save the file
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);
}
}
}
A header can provide useful information about the document's content, such as its title, author, date, and page numbers. This helps readers understand the document's purpose and navigate it more easily. In addition, including a logo or company name in the header reinforces brand identity and helps readers associate the document with a particular organization or business. In this article, you will learn how to add a header to an existing PDF document in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF 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.PDF
Background Knowledge
When an existing PDF document is manipulated by Spire.PDF for .NET, the origin of the coordinate system is located at the top left corner of the page, with the x-axis extending to the right and the y-axis extending downward. Adding a header to a page means adding content, such as text, images, automatic fields and shapes, to a specified location in the upper blank area of the page.

If the blank area is not large enough to accommodate the content you want to add, you can consider increasing the PDF page margins.
Add a Header to an Existing PDF Document in C# and VB.NET
Spire.PDF for .NET allows users to draw text, images and shapes on a PDF page using PdfCanvas.DrawString() method, PdfCanvas.DrawImage() method, PdfCanvas.DrawLine() and other similar methods. To add dynamic information to the header, such as page numbers, sections, dates, you need to resort to automatic fields. Spire.PDF for .NET provides the PdfPageNumberField class, PdfSectionNumberField class, PdfCreationDateField class, etc. to achieve the dynamic addition of these data.
The following are the steps to add a header consisting of text, an image, a date, and a line to a PDF document using Spire.PDF for .NET.
- Create a PdfDocument object.
- Load a PDF document using PdfDocument.LoadFromFile() method.
- Create font, pen and brush objects that will be used to draw text or shapes.
- Draw text on the top blank area of a page using PdfPageBase.Canvas.DrawString() method.
- Draw a line on the top blank area of a page using PdfPageBase.Canvas.DrawLine() method.
- Load an image using PdfImage.FromFile() method.
- Draw the image on the top blank area of a page using PdfPageBase.Canvas.DrawImage() method.
- Create a PdfCreationDateField object that reflects the creation time of the document.
- Draw the creation time on the top blank area of a page using PdfCreationDateField.Draw() method.
- Save the document to another PDF file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.AutomaticFields;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddHeaderToExistingPdf
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\TargetMarket.pdf");
//Load an image for the header
PdfImage headerImage = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\logo.png");
//Get image width in pixel
float width = headerImage.Width;
//Convert pixel to point
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
float pointWidth = unitCvtr.ConvertUnits(width, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
//Specify text for the header
string headerText = "E-iceblue Tech\nwww.e-iceblue.com";
//Create a true type font
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 12f, FontStyle.Bold), true);
//Create a brush
PdfBrush brush = PdfBrushes.Purple;
//Create a pen
PdfPen pen = new PdfPen(brush, 1.0f);
//Create a creation date field
PdfCreationDateField creationDateField = new PdfCreationDateField(font, brush);
creationDateField.DateFormatString = "yyyy-MM-dd";
//Create a composite field to combine static string and date field
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "creation time: {0}", creationDateField);
compositeField.Location = new Point(55, 48);
//Loop through the pages in the document
for (int i = 0; i < doc.Pages.Count; i++)
{
//Get specific page
PdfPageBase page = doc.Pages[i];
//Draw the image on the top blank area
page.Canvas.DrawImage(headerImage, page.ActualSize.Width - pointWidth - 55, 20);
//Draw text on the top blank area
page.Canvas.DrawString(headerText, font, brush, 55, 20);
//Draw a line on the top blank area
page.Canvas.DrawLine(pen, new PointF(55, 70), new PointF(page.ActualSize.Width - 55, 70));
//Draw the composite field on the top blank area
compositeField.Draw(page.Canvas);
}
//Save to file
doc.SaveToFile("AddHeader.pdf");
doc.Dispose();
}
}
}

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.
Spire.Doc offers the property ShapeObject. HorizontalAlignment and ShapeObject. Vertical Alignment to enable developers to align the shapes horizontally or vertically. This article will show you to how to align the shapes on the word document in C#.
Step 1: Create a new instance of word document and load the document from file.
Document doc = new Document();
doc.LoadFromFile("Sample.docx");
Step 2: Get the first section from file.
Section section = doc.Sections[0];
Step 3: Traverse the word document and set the horizontal alignment as left.
foreach (Paragraph para in section.Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj is ShapeObject)
{
(obj as ShapeObject).HorizontalAlignment = ShapeHorizontalAlignment.Left;
}
}
}
Step 4: Save the document to file.
doc.SaveToFile("Result.docx", FileFormat.Docx);
Effective screenshot after setting the alignment of the shapes.


Full codes:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace AlignShape
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("Sample.docx");
Section section = doc.Sections[0];
foreach (Paragraph para in section.Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj is ShapeObject)
{
(obj as ShapeObject).HorizontalAlignment = ShapeHorizontalAlignment.Left;
////Set the vertical alignment as top
//(obj as ShapeObject).VerticalAlignment = ShapeVerticalAlignment.Top;
}
}
}
doc.SaveToFile("Result.docx", FileFormat.Docx2013);
}
}
}
Adding shadow effect is one of the good ways to make a data label stand out on your chart. This article is going to show you how to add shadow effect to a chart data label in PowerPoint using Spire.Presentation.
Detail steps:
Step 1: Initialize a Presentation object and load the PowerPoint file.
Presentation ppt = new Presentation(); ppt.LoadFromFile(@"test.pptx");
Step 2: Get the chart.
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
Step 3: Add a data label to the first chart series.
ChartDataLabelCollection dataLabels = chart.Series[0].DataLabels; ChartDataLabel Label = dataLabels.Add(); Label.LabelValueVisible = true;
Step 4: Add outer shadow effect to the data label.
Label.Effect.OuterShadowEffect = new OuterShadowEffect(); //Set shadow color Label.Effect.OuterShadowEffect.ColorFormat.Color = Color.Yellow; //Set blur Label.Effect.OuterShadowEffect.BlurRadius = 5; //Set distance Label.Effect.OuterShadowEffect.Distance = 10; //Set angle Label.Effect.OuterShadowEffect.Direction = 90f;
Step 5: Save the file.
ppt.SaveToFile("Shadow.pptx", FileFormat.Pptx2010);
Screenshot:

Full code:
using System.Drawing;
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Collections;
using Spire.Presentation.Drawing;
namespace Add_Shadow_Effect_to_Chart_Datalabel
{
class Program
{
static void Main(string[] args)
{
//Initialize a Presentation object
Presentation ppt = new Presentation();
//Load the PowerPoint file
ppt.LoadFromFile(@"test.pptx");
//Get the chart
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
//Add a data label to the first chart series
ChartDataLabelCollection dataLabels = chart.Series[0].DataLabels;
ChartDataLabel Label = dataLabels.Add();
Label.LabelValueVisible = true;
//Add outer shadow effect to the data label
Label.Effect.OuterShadowEffect = new OuterShadowEffect();
//Set shadow color
Label.Effect.OuterShadowEffect.ColorFormat.Color = Color.Yellow;
//Set blur
Label.Effect.OuterShadowEffect.BlurRadius = 5;
//Set distance
Label.Effect.OuterShadowEffect.Distance = 10;
//Set angle
Label.Effect.OuterShadowEffect.Direction = 90f;
//Save the file
ppt.SaveToFile("Shadow.pptx", FileFormat.Pptx2010);
}
}
}
Spire.Doc supports to insert new shapes to the word document and from version 6.4.11, Spire.Doc public the property ShapeObject.Rotation to enable developers to rotate the shapes. This article will show you to how to rotate the shapes on the word document in C#.
Step 1: Create a new instance of word document and load the document from file.
Document doc = new Document();
doc.LoadFromFile("Sample.docx");
Step 2: Get the first section from file.
Section section = doc.Sections[0];
Step 3: Traverse the word document and set the shape rotation as 10.
foreach (Paragraph para in section.Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj is ShapeObject)
{
(obj as ShapeObject).Rotation = 10.0;
}
}
}
Step 4: Save the document to file.
doc.SaveToFile("Result.docx", FileFormat.Docx);
Effective screenshot after rotate the shapes:

Full codes:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Rotate
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("Sample.docx");
Section section = doc.Sections[0];
foreach (Paragraph para in section.Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj is ShapeObject)
{
(obj as ShapeObject).Rotation = 10.0;
}
}
}
doc.SaveToFile("Result.docx", FileFormat.Docx);
}
}
}
This tutorial is going to show you how to make a color of a image transparent using Spire.Doc.
Below screenshot shows an example image with black and white colors:

Detail steps:
Step 1: Instantiate a Document object and Load the Word file.
Document doc = new Document();
doc.LoadFromFile("Input.docx");
Step 2: Get the first Paragraph in the first section.
Paragraph paragraph = doc.Sections[0].Paragraphs[0];
Step 3: Set the black color of the image(s) in the paragraph to transperant.
foreach (DocumentObject obj in paragraph.ChildObjects)
{
if (obj is DocPicture)
{
(obj as DocPicture).TransparentColor = Color.Black;
}
}
Step 4: Save the file.
doc.SaveToFile("Result.docx", FileFormat.Docx2013);
Screenshot:

Full code:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Transeperant
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Document object
Document doc = new Document();
//Load the Word file
doc.LoadFromFile("Input.docx");
//Get the first paragraph in the first section
Paragraph paragraph = doc.Sections[0].Paragraphs[0];
//Set the black color of the image(s) in the paragraph to transperant
foreach (DocumentObject obj in paragraph.ChildObjects)
{
if (obj is DocPicture)
{
(obj as DocPicture).TransparentColor = Color.Black;
}
}
//Save the file
doc.SaveToFile("Result.docx", FileFormat.Docx2013);
}
}
}
When you need to share an Excel file with others but don't want to give them access to the underlying formulas, converting the formulas to numeric values ensures that the recipients can view and work with the calculated results without altering the original calculations. In this article, you will learn how to programmatically remove formulas from cells in Excel but keep the values using Spire.XLS for .NET.
Install Spire.XLS for .NET
To begin with, you need to add the DLL files included in the Spire.XLS 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.XLS
Remove Formulas from Excel Cells but Keep Values in C#
MS Excel provides the "Paste Values" function to help remove formulas while keeping the values. To implement the same functionality in C# through code, refer to the below steps.
- Create a Workbook instance.
- Load a sample Excel file using Workbook.LoadFromFile() method.
- Loop through the worksheets in the file, and then loop through the cells in each sheet.
- Determine whether the cell contains a formula using CellRange.HasFormula property.
- If yes, get the formula value using CellRange.FormulaValue property. Then clear the original formula in the cell and fill it with the formula value using CellRange.Value2 property.
- Save the result file using Workbook.SaveToFile() method.
- C#
using Spire.Xls;
using System;
namespace RemoveFormulas
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load an Excel file
workbook.LoadFromFile("Sample.xlsx");
//Loop through worksheets
foreach (Worksheet sheet in workbook.Worksheets)
{
//Loop through cells
foreach (CellRange cell in sheet.Range)
{
//Determine whether the cell contain formula
if (cell.HasFormula)
{
//If yes, get the formula value in the cell
Object value = cell.FormulaValue;
//Clear cell content
cell.Clear(ExcelClearOptions.ClearContent);
//Fill the formula value into the cell
cell.Value2 = value;
}
}
}
//Save the result file
workbook.SaveToFile("DeleteFormula.xlsx", ExcelVersion.Version2016);
}
}
}

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.
Create Multiple Slide Maters and Apply Them to Individual Slides in C#, VB.NET
2018-05-03 09:09:22 Written by KoohjiWhen you want to use multiple themes in one presentation, you’ll need multiple slide masters. In this article, you will learn how create additional slide masters and apply them to different slides, by using Spire.Presentation with C# and VB.NET.
Step 1: Create a PowerPoint document and insert four slides to it. There are five slides in total including the default slide.
Presentation ppt = new Presentation();
for (int i = 0; i < 4; i++)
{
ppt.Slides.Append();
}
Step 2: Get the first default slide master.
IMasterSlide first_master = ppt.Masters[0];
Step 3: Append another slide master.
ppt.Masters.AppendSlide(first_master); IMasterSlide second_master = ppt.Masters[1];
Step 4: Set different background image for the two slide masters.
string pic1 = @"C:\Users\Administrator\Desktop\image-1.png"; string pic2 = @"C:\Users\Administrator\Desktop\image-2.png"; RectangleF rect = new RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height); first_master.SlideBackground.Fill.FillType = FillFormatType.Picture; IEmbedImage image1 = first_master.Shapes.AppendEmbedImage(ShapeType.Rectangle, pic1, rect); first_master.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image1 as IImageData; second_master.SlideBackground.Fill.FillType = FillFormatType.Picture; IEmbedImage image2 = second_master.Shapes.AppendEmbedImage(ShapeType.Rectangle, pic2, rect); second_master.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image2 as IImageData;
Step 5: Apply the first master with layout to the first slide.
ppt.Slides[0].Layout = first_master.Layouts[1];
Step 6: Apply the second master with layout to other slides.
for (int i = 1; i < ppt.Slides.Count; i++)
{
ppt.Slides[i].Layout = second_master.Layouts[8];
}
Step 7: Save the file.
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
Output:

Full Code:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace CreateMultipleMaster
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.SlideSize.Type = SlideSizeType.Screen16x9;
for (int i = 0; i < 4; i++)
{
ppt.Slides.Append();
}
IMasterSlide first_master = ppt.Masters[0];
ppt.Masters.AppendSlide(first_master);
IMasterSlide second_master = ppt.Masters[1];
string pic1 = @"C:\Users\Administrator\Desktop\image-1.png";
string pic2 = @"C:\Users\Administrator\Desktop\image-2.png";
RectangleF rect = new RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height);
first_master.SlideBackground.Fill.FillType = FillFormatType.Picture;
IEmbedImage image1 = first_master.Shapes.AppendEmbedImage(ShapeType.Rectangle, pic1, rect);
first_master.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image1 as IImageData;
second_master.SlideBackground.Fill.FillType = FillFormatType.Picture;
IEmbedImage image2 = second_master.Shapes.AppendEmbedImage(ShapeType.Rectangle, pic2, rect);
second_master.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image2 as IImageData;
ppt.Slides[0].Layout = first_master.Layouts[1];
for (int i = 1; i < ppt.Slides.Count; i++)
{
ppt.Slides[i].Layout = second_master.Layouts[8];
}
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace CreateMultipleMaster
Class Program
Private Shared Sub Main(args As String())
Dim ppt As New Presentation()
ppt.SlideSize.Type = SlideSizeType.Screen16x9
For i As Integer = 0 To 3
ppt.Slides.Append()
Next
Dim first_master As IMasterSlide = ppt.Masters(0)
ppt.Masters.AppendSlide(first_master)
Dim second_master As IMasterSlide = ppt.Masters(1)
Dim pic1 As String = "C:\Users\Administrator\Desktop\image-1.png"
Dim pic2 As String = "C:\Users\Administrator\Desktop\image-2.png"
Dim rect As New RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height)
first_master.SlideBackground.Fill.FillType = FillFormatType.Picture
Dim image1 As IEmbedImage = first_master.Shapes.AppendEmbedImage(ShapeType.Rectangle, pic1, rect)
first_master.SlideBackground.Fill.PictureFill.Picture.EmbedImage = TryCast(image1, IImageData)
second_master.SlideBackground.Fill.FillType = FillFormatType.Picture
Dim image2 As IEmbedImage = second_master.Shapes.AppendEmbedImage(ShapeType.Rectangle, pic2, rect)
second_master.SlideBackground.Fill.PictureFill.Picture.EmbedImage = TryCast(image2, IImageData)
ppt.Slides(0).Layout = first_master.Layouts(1)
For i As Integer = 1 To ppt.Slides.Count - 1
ppt.Slides(i).Layout = second_master.Layouts(8)
Next
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
Every PowerPoint presentation has a slide master which contains all the styles for your slides. You can quickly change the look of your entire presentation by selecting the slide master, and then adopting a theme, adding a background picture or changing the color scheme.
In this article, you will learn how to access and customize the slide master in an existing presentation.
Source File:

Detail steps:
Step 1: Load the source file.
Presentation ppt = new Presentation(); ppt.LoadFromFile(@"sample.pptx");
Step 2: Get the first slide master from the presentation.
IMasterSlide masterSlide = ppt.Masters[0];
Step 3: Customize the background of the slide master.
string backgroundPic = "background.png"; RectangleF rect = new RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height); masterSlide.SlideBackground.Fill.FillType = FillFormatType.Picture; IEmbedImage image = masterSlide.Shapes.AppendEmbedImage(ShapeType.Rectangle, backgroundPic, rect); masterSlide.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image as IImageData;
Step 4: Change the color scheme.
masterSlide.Theme.ColorScheme.Accent1.Color = Color.Red; masterSlide.Theme.ColorScheme.Accent2.Color = Color.RosyBrown; masterSlide.Theme.ColorScheme.Accent3.Color = Color.Ivory; masterSlide.Theme.ColorScheme.Accent4.Color = Color.Lavender; masterSlide.Theme.ColorScheme.Accent5.Color = Color.Black;
Step 5: Add an image to the slide master. If you want, you can add any other document elements to slide master so that they can display on each slide.
string logo = "logo.png"; IEmbedImage imageShape = masterSlide.Shapes.AppendEmbedImage(ShapeType.Rectangle, logo, new RectangleF(40, 40, 240, 65)); imageShape.Line.FillFormat.FillType = FillFormatType.None;
Step 6: Save the document.
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
Result:

Full code:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace ApplySlideMaster
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"sample.pptx");
IMasterSlide masterSlide = ppt.Masters[0];
string backgroundPic = "background.png";
string logo = "logo.png";
RectangleF rect = new RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height);
masterSlide.SlideBackground.Fill.FillType = FillFormatType.Picture;
IEmbedImage image = masterSlide.Shapes.AppendEmbedImage(ShapeType.Rectangle, backgroundPic, rect);
masterSlide.SlideBackground.Fill.PictureFill.Picture.EmbedImage = image as IImageData;
masterSlide.Theme.ColorScheme.Accent1.Color = Color.Red;
masterSlide.Theme.ColorScheme.Accent2.Color = Color.RosyBrown;
masterSlide.Theme.ColorScheme.Accent3.Color = Color.Ivory;
masterSlide.Theme.ColorScheme.Accent4.Color = Color.Lavender;
masterSlide.Theme.ColorScheme.Accent5.Color = Color.Black;
IEmbedImage imageShape = masterSlide.Shapes.AppendEmbedImage
(ShapeType.Rectangle, logo, new RectangleF(40, 40, 240, 65));
imageShape.Line.FillFormat.FillType = FillFormatType.None;
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace ApplySlideMaster
Class Program
Private Shared Sub Main(args As String())
Dim ppt As New Presentation()
ppt.LoadFromFile("sample.pptx")
Dim masterSlide As IMasterSlide = ppt.Masters(0)
Dim backgroundPic As String = "background.png"
Dim logo As String = "logo.png"
Dim rect As New RectangleF(0, 0, ppt.SlideSize.Size.Width, ppt.SlideSize.Size.Height)
masterSlide.SlideBackground.Fill.FillType = FillFormatType.Picture
Dim image As IEmbedImage = masterSlide.Shapes.AppendEmbedImage(ShapeType.Rectangle, backgroundPic, rect)
masterSlide.SlideBackground.Fill.PictureFill.Picture.EmbedImage = TryCast(image, IImageData)
masterSlide.Theme.ColorScheme.Accent1.Color = Color.Red
masterSlide.Theme.ColorScheme.Accent2.Color = Color.RosyBrown
masterSlide.Theme.ColorScheme.Accent3.Color = Color.Ivory
masterSlide.Theme.ColorScheme.Accent4.Color = Color.Lavender
masterSlide.Theme.ColorScheme.Accent5.Color = Color.Black
Dim imageShape As IEmbedImage = masterSlide.Shapes.AppendEmbedImage(ShapeType.Rectangle, logo, New RectangleF(40, 40, 240, 65))
imageShape.Line.FillFormat.FillType = FillFormatType.None
ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace