Set image background for word document in C#

We have already demonstrated how to set gradient background for word document in C#. Besides the gradient background, Spire.Doc also supports to add image background for word document. This article will show you how to set image background for word document in C#.

Step 1: Create a new word document and load the document from file.

Document document = new Document();
document.LoadFromFile("Sample.docx", FileFormat.Docx2010);

Step 2: Set the background type as picture.

document.Background.Type = BackgroundType.Picture;

Step 3: Load the image from file.

document.Background.Picture = Image.FromFile("background.jpg");

Step 4: Save the document to file.

document.SaveToFile("Result.docx", FileFormat.Docx2010);

Effective screenshot of adding image background for word document:

Set image background for word document in C#

Full codes of how to set image background for word document:

{
    Document document = new Document();
    document.LoadFromFile("Sample.docx", FileFormat.Docx2010);

    document.Background.Type = BackgroundType.Picture;
                     
    document.Background.Picture = Image.FromFile("background.jpg");
       
    document.SaveToFile("Result.docx", FileFormat.Docx2010);
}